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

Question

Question

Prevent commas with the modern designer

asked on September 9, 2024

I have a form that eventually gets exported to excel, so commas are a problem upon exporting. Is there a way to prevent the user from entering commas with the modern designer? 

0 0

Answer

SELECTED ANSWER
replied on September 10, 2024
//Commas and Other Value length

const fields = LFForm.findFields(f => 	
    (f.componentType == "Checkbox"  || f.componentType == "Radio") ||
	(f.componentType == "SingleLine" || f.componentType == "MultiLine")) 
;
fields.forEach(f => {
    let fld = LFForm.findFieldsByFieldId(f.fieldId)[0];    
  	if (f.componentType == "SingleLine" || f.componentType == "MultiLine") {
     	LFForm.onFieldChange(() => { RemoveCommas(f.fieldId); }, fld);         
    }
  	else {
		LFForm.onFieldChange(() => { ValidateOtherField(f.fieldId); }, fld);  
    }
});
function RemoveCommas(fldId){
	console.log(fldId);
  let fld = LFForm.findFieldsByFieldId(fldId)[0];
    let fldValue = LFForm.getFieldValues({fieldId: fldId});
  	if (fldValue.indexOf(',') > 0){
    	let newVal = fldValue.replaceAll(',',''); 
        LFForm.setFieldValues(fld, newVal);
        LFForm.changeFieldSettings(fld, {
          "subtext": "<b>Note:</b> Comma(s) have been removed."
        });   
    }  
}

Use this JS with the css class .otherchoice in the fields you don't want commas allowed.

1 0
replied on September 11, 2024

Thanks Angela! This worked perfectly.

 

0 0

Replies

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

Sign in to reply to this post.