We know that it is very easy to set the Change event for a field through the interface, whether it is required or not. But sometimes we need to dynamically according to certain conditions to set, then there is a need to use JS to dynamically control.
The following describes how to use JS to dynamically set.
The change event of a dynamic set field
Form on Load Event
function onLoad () {
Init ();
PageAttr.delivery_from.addOnChange (Deliveryfromchange);
PageAttr.type.addOnChange (Typechange);
PageAttr.order_purpose.addOnChange (Orderpurposechange);
PageAttr.ship_toid.addOnChange (Getshiptoinfo);
PageAttr.sold_toid.addOnChange (Orderbychange);
}
one of the Init methods and pageattr, page please refer to my blog " Dynamic CRM 2013 Learning notes (23) CRM JS Smart Tips (CRM-related methods, properties, and Page fields), and pre-release debugging "
Addonchange here is the same as in the form page, add Field onchange event, but in JS more flexible
Two, the Dynamic setting field is required to fill or cancel required
Set Required method: Setrequiredlevel (' Required ')
Cancellation Required: Setrequiredlevel (' none ')
var df = PageAttr.delivery_from.getText ();
if "Others") {
PageAttr.deliveryfrom_plsspecify.setRequiredLevel (' required ');
}
Else {
PageAttr.deliveryfrom_plsspecify.setRequiredLevel (' none ');
}
Third, dynamic set field is visible
Set Visible: SetVisible (True)
Setting not visible: setvisible (False)
var op = pageAttr.order_purpose.getText ();
if "Replacement of Return materials") {
Page.rma_noid.setVisible (true);
}
Else {
Page.rma_noid.setVisible (false);
}
But it's important to note that this is not a attribute here, it can only be set on control.
Dynamic CRM 2013 Learning Notes Series Rollup-ongoing updates
Dynamic CRM 2013 Learning notes (28) Dynamically set field change events, required fields, and visible with JS