Make fields required and not required

Hi Team,

I want to make some fields required when submit button clicks but make that fields not required when save button clicks.

I tried to code it on Click function of buttons but it's not working.

Example:Want to make highlighted fields required on Submit button click and not required on save button click.

.

Thank you in advance.
Navpreet

Dear @navpreet,
If fields are selected as required in SharePoint List Settings - it cannot be changed with JavaScript, the validation is happening on the server. If they're not, you should be able to just use it like this:

fd.field('MyField').required = false;
fd.save();

Hi,
I am using this, but it redirects the form to the submitURL instead of giving validation error.

Dear @navpreet,
Yes, it's making fields not required - they should be made required first in fd.spRendered():

fd.spRendered(function(){
    fd.field('MyField').required = true;
});

Then, you can have two submit buttons. One which keeps field required:

fd.save();

One which makes it not required (add a small timeout to make sure fields have time to change state):

fd.field('MyField').required = false;
setTimeout(function() { fd.save() }, 500);

Hi @Nikita_Kurguzov,

Thank you so much it worked.

Regards
Navpreet

1 Like