Domanda

In HTML il tag selezionato ha il necessario attributo che "specifica che l'utente è tenuto a selezionare un valore prima di inviare il modulo". Leggi qui

In Struts 1 il tag "HTML: Select" non ha l'attributo "necessario": Leggi qui

Come posso specificare che l'utente è richiesto per selezionare un valore prima di inviare il modulo in Struts 1 per la casella di selezione?

<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>
È stato utile?

Soluzione

Prova qualcosa del genere, Javascript

JQuery

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

Se hai bisogno di questo in HTMT TLD di quanto devi modificare HTML TLD e devi aggiungere codice personalizzato ad esso e rispettiva classe Java

Altri suggerimenti

Aggiungi il required Proprietà nel <html:select /> Tag e devi avere un'opzione vuota.

Esempio:

<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>

Questo funziona per me - avere il primo valore vuoto - richiesto funziona su valori vuoti.

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

L'attributo richiesto è un attributo booleano. Se specificato, l'utente dovrà selezionare un valore prima di inviare il modulo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top