Search code examples
htmlstruts-1taglib

How to make <html:select> tag REQUIRED


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>

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