質問

I have radio buttons for a online form. Following the [URL="https://netsuite.custhelp.com/app/answers/detail/a_id/14704/"]NS help page for radio buttons[/URL], I made my fields free-form-text. I went to the Online Form record (Setup -> Marketing -> Online Customer Forms) and tried to make the radio button fields mandatory. While it keeps the "Yes" for Mandatory, it doesn't seem to apply it when I process the form.

Is there something I have to do to make Free-form-text fields mandatory?

役に立ちましたか?

解決 2

NetSuite's Mandatory appears to look at the Value attribute in a form element (radio button), it may be getting the value of the first radio button in a group, even if none are checked, and see there is something there. Because of this, I solved this issue with an HTML5 element and Javascript. I am answering my own question to help others with this:

HTML5 Approach:
The easy way is in HTML5 input fields have a new attribute called "required". Just add this to the end of the input tag and it will make the field required. Any HTML5 compliant browser will handle this. Example is:

<input value="Very Satisfied" name="custrecord208" type="radio" id="custrecord208" class="radio1" required>Very Satisfied 

Javascript Approach:
Unfortunately, not all users use the latest browsers (HTML5 compliant) much to developers' dismay. Below is the code I wrote in Javascript for this particular problem. It may not be the cleanest but it got the job done.

function saveRecord_validation(){
//array of the id's you know you need to go through
var a_custRecNames = ['custrecord184', 'custrecord185', 'custrecord186', 'custrecord187', 'custrecord188'];
var s_quesNums=""; 
var isFormValid = true;
var isRadioChecked = false;
for( var i = 0; i < a_custRecNames.length; i++ ) {//loop through each mandatory customRecord
    var radios = document.getElementsByName(a_custRecNames[i]); //get the radio buttons for that question

    //reset isRadioChecked for each question
    isRadioChecked = false;
    for (var j = 0, length = radios.length; j < length; j++) {//loop through each radio button
        if (radios[j].checked) {
            // only one radio can be logically checked, don't check the rest
            isRadioChecked = true;
            break;
        }
    }   
    if(!isRadioChecked){
//cleaning up the output just a little.
        s_quesNums = ((i+1) < a_custRecNames.length) ? s_quesNums.concat(i+1).concat(", ") : s_quesNums.concat(i+1)+".";
        isFormValid = false;
    }
}
if(!isFormValid){
    alert( "Please answer question(s) "+s_quesNums);
    return false;
}
return true;
} 

Add this to the Online Form in NetSuite (for help visit NetSuite Answers: Attach Script to Form).

For help with creating Radio Buttons in NetSuite to begin with, visit NetSuite Answers: Use Radio Button values on Online HTML forms

他のヒント

I dont think radio buttons can be made mandatory since they only hold a Yes/No value. If you do not select anything, it will default to No. This is the same case with checkboxes.

For mandatory fields, I think the system looks for null or empty values.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top