Fórum

In alloy-ui how to validate select field....

Ramya Sree Kalagiri, modificado 11 Anos atrás.

In alloy-ui how to validate select field....

New Member Postagens: 8 Data de Entrada: 19/12/12 Postagens Recentes
Hi all,
how to validate select field as mandatory only when it's corresponding text field is entered?
For example
<aui:form name="temp">
<aui:input type="text" name="temperature"/>
<aui:select label="" name="unit">
<aui:option value="" >--select--</aui:option>
<aui:option value="hello">Celcius</aui:option>
<aui:option value="hello hi">Fahrenheit </aui:option>
</aui:select>
<aui:input type="submit" name="submit"/>
</aui:form>


Here using alloy-ui validations how to generate validation error when temperature is entered but unit has not chosen?

Note:It is not mandatory that always temperature should be entered


can any please help me out.....
thumbnail
Hitoshi Ozawa, modificado 11 Anos atrás.

RE: In alloy-ui how to validate select field....

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Check the following page to see form validation with alloy ui.

http://rajeevalochanabr.wordpress.com/2012/08/20/validation-using-auialloy-user-interface-script-and-html-form/
Ramya Sree Kalagiri, modificado 11 Anos atrás.

RE: In alloy-ui how to validate select field....

New Member Postagens: 8 Data de Entrada: 19/12/12 Postagens Recentes
Hi,
thank you for the reply. I know how to validate select as required. But I want to know how validation on select will be done only when the text field(temperature) is entered.
Ramya Sree Kalagiri, modificado 11 Anos atrás.

RE: In alloy-ui how to validate select field....

New Member Postagens: 8 Data de Entrada: 19/12/12 Postagens Recentes
Can any one please solve my question soon? I need it urgently.... thanks in advance.
Joe Pinto, modificado 9 Anos atrás.

RE: In alloy-ui how to validate select field....

New Member Postagens: 4 Data de Entrada: 21/02/14 Postagens Recentes
I may be a little late here...

try to think it like this:
instead of saying 'this field is always required' like in 'required: true' you should say 'this field is required when temperature is set'


function isTemperatureSet(){ 
    if( $('#temperature').val() != ""){
        return true;
    }
    return false;
}

var rules = {
   <portlet:namespace />unit: {
       required: isTemperatureSet  
   }
};



please be aware i'm using jQuery in my answer to get the value of the temperature field.. plus,
  if( $('#temperature').val() != "")
does not work for whitespaced strings, etc