Question

In HTML the select tag has the required attribute that "Specifies that the user is required to select a value before submitting the form". read here

In Struts 1 the "html:select" tag doesn't have the attribute "required": read here

How can I specify that the user is required to select a value before submitting the form in Struts 1 for the select box?

<td class="insdataheader">
    <label for="initReqList[0].seqType">
         <bean:message bundle="XYZ" key="it.myproject.cbi2.disposals.v000104.model.MndtInitiationRequestV02.seqType"/>
    </label>
</td>

<td class="insdatitxt_inserita_nowrap" align="left">
    <html:select property="initReqList[0].seqType" name="initReqList[0].seqType" styleId="initReqList[0].seqType" value="${dataEntryForm.initReqList[0].seqType}">
          <html-ext:keyOptionsCollection bundle="XYZ" name="dataEntryForm" property="initReqList[0].seqTypeOptions" label="keyBundle"value="key"  
   </html:select>
</td>
Was it helpful?

Solution

try something like this,javascript

JQuery

 $(function(){
            var elem = document.getElementsByName('initReqList[0].seqType')[0];
            jQuery(elem).attr('required','required');
        });

if need this in htmt tld than you have to edit html tld and have to add custom code to it and respective java class

OTHER TIPS

Add the required property in the <html:select /> tag and you must have an empty option.

Example:

<html:select required="required" property="initReqList[0].seqType" name="initReqList[0].seqType" styleId="initReqList[0].seqType" value="${dataEntryForm.initReqList[0].seqType}">
    <html-ext:keyOptionsCollection bundle="XYZ" name="dataEntryForm" property="initReqList[0].seqTypeOptions" label="keyBundle"value="key"  
</html:select>

This works for me - Have the first value empty - required works on empty values.

<select required>
 <option value="">Please select</option>
 <option value="one">One</option>
 <option value="two">Two</option>
</select>

The required attribute is a boolean attribute. When specified, the user will be required to select a value before submitting the form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top