You are viewing limited content. For full access, please sign in.

Question

Question

LFForm object set field required or not required

asked on November 1, 2024

I've not found an appropriate example in the forums, but I simply want to change different fields as required/not required depending on a list selection. 

I'm using self-hosted Forms v11 update 5. 

 

 

LFForm.onFieldChange(() => grantOriginNum(), {fieldId: 45});
function grantOriginNum(){
  //the list selector
  let grantOrigin = LFForm.getFieldValues({fieldId: 45});
  
  if(grantOrigin == 'Federal'){
    LFForm.setFieldValues({fieldId: 38}, "Federal");
    LFForm.changeFieldSettings({fieldId:12}, {required: "true"});
  }
  if(grantOrigin == 'State'){
    LFForm.setFieldValues({fieldId: 38}, "State");
    LFForm.changeFieldSettings({fieldId:43}, {required: "true"});
  }
  if(grantOrigin == 'Other'){
    LFForm.setFieldValues({fieldId: 38}, "Other");
    LFForm.changeFieldSettings({fieldId:46}, {required: "true"});
  }
}

0 0

Answer

SELECTED ANSWER
replied on November 1, 2024

You can. For the first part of the Field Rule set it to Validate:

Then you can choose "as required field" or "as optional field":

4 0

Replies

replied on November 1, 2024

Dustin, you should be able to what you are needing using Field Rules.

0 0
replied on November 1, 2024

@████████I am also looking for a solution to change some fields to required depending on a specific field value. 

I think you are on the right track, but I do think the "true" in your statements should be true without the quotes. Please see example below. 

I have my example set up like this and it still isn't working. 

@████████I know we can disable fields based on input values, but using field rules I don't see an option to make fields required? I know we could hide the field, but some clients just want to make the field required, not show it. Does that make sense? 

0 0
SELECTED ANSWER
replied on November 1, 2024

You can. For the first part of the Field Rule set it to Validate:

Then you can choose "as required field" or "as optional field":

4 0
replied on November 4, 2024

I will try this option, but if someone knows how to do it in JS that would be superb.

0 0
replied on November 4, 2024

While it's not my preferred way, the field rules will accomplish what I need. Thank you Blake!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.