Showing/hiding/requirng a field based on values of a choice field

So I have one choice field with 4 choices. when any of 2 choices are picked, I want to show another field and make it required. I have this code:

fd.spRendered(function() {

 $(fd.field('Fixed_x0020_Fee_x0020_Billing_x0').$parent.$el).hide()

});

fd.spRendered(function(){
fd.field('invoice_x0020_type').$on('change', function(value){
if(value.includes('Milestone Fixed Fee')){
$(fd.field('Fixed_x0020_Fee_x0020_Billing_x0').$parent.$el).show();
}
if(value.includes('Monthly Fixed Fee')){
$(fd.field('Fixed_x0020_Fee_x0020_Billing_x0').$parent.$el).show();
}
if(value.includes('Time and Materials')){
$(fd.field('Fixed_x0020_Fee_x0020_Billing_x0').$parent.$el).hide();
}
if(value.includes('Not to Exceed')){
$(fd.field('Fixed_x0020_Fee_x0020_Billing_x0').$parent.$el).hide();
}
});
});

it work in the sense that it shows and hides fields as appropriate

How can I easily make the field I show to be required?

thanks for anyone that can help

Eric Weiler

Hello @eweiler,

You can make field required using the required property:

//make field required
fd.field('Field0').required = true;

//make field optional
fd.field('Field0').required = false;

Awesome!, thank you!

1 Like