问题
I have to fields on the same Dynamics CRM form. One is Account Name and the other field is Company. They both share the same field id name which is parentcustomerid. I need to show/hide these fields based on the value of an option set of another field. I can get the Account name field to show/hide but the Company field will not show/hide.
function showHideSourceField() {
var type = Xrm.Page.data.entity.attributes.get("new_type").getValue(); var source = Xrm.Page.ui.controls.get("new_source"); var accountname = Xrm.Page.ui.controls.get("parentcustomerid"); var company = Xrm.Page.ui.controls.get("parentcustomerid"); //Type of Contact is Unaffiliated if (type == 100000004) { source.setVisible(true); accountname.setVisible(false); company.setVisible(false);
回答1:
You have two possibilities:
1) They are two different fields, and you can simply check this in the form editor, for example one is name
the other is parentcustomerid
2) They are the same field added twice to the form, this is possible inside Dynamics CRM, in this case the first field is parentcustomerid
an the second is parentcustomerid1
, and you can still check if it is the same field inside the form editor.
回答2:
You mean same name
attribute?
In Html you use:
id
to provide a unique identifier.class
to provide a group/type/etc
I think the best solution for this is to provide a distinct name for each and use the same class for both.
<input id="account-name" class="parentcustomer" name="account" />
<input id="company" class="parentcustomer" name="company" />
Then you can:
$('.parentcustomer').hide();
$('.parentcustomer').show();
来源:https://stackoverflow.com/questions/32870531/using-javascript-to-show-hide-multiple-fields-on-the-same-form-with-same-id-name