jQuery UI Widgets › Forums › Plugins › Validator, Drag & Drop, Sortable › Validation only if has data
Tagged: validation
This topic contains 3 replies, has 2 voices, and was last updated by david 11 years, 8 months ago.
-
Author
-
Hello!!
I need your help to validate my form.I have a form in a jqxWindow like this:
<div id="UserRenewWindow" style="top:300px;"> <div id="UserRenewWindowHeader"> <span id="captureContainer" style="float: left">Recordar Usuario y Contraseña</span> </div> <div style="overflow: hidden;" id="windowContent"> <form id="UserRenewForm"> <div style="text-align:center; color:red"> <span id="error"> </span> </div> <div style="text-indent: 2em;">Introduzca el Usuario y le mandaremos su nueva contraseńa a su correo electrónico asociado, o bien el correo electrónico y le mandaremos su usuario y una nueva contraseńa. </div> <br/> <label class="lab" id="usarR" for="usuario">Usuario:</label> <input type="text" class="field" id="idUsuR" value="" /> <br> <label class="lab" id="emailR" for="e-mail">Correo electrónico</label> <input type="email" class="field" id="idEmailR" name="emailR" value=""/> <br><br> <div style="text-align: center"> <input type="button" id="UserRenewButton" data-i18n="UserRenewButton" /> </div> </form> </div> </div>
It draws a form where you can choose if you send me your user or your e-mail and i will use it/them.
my JS looks is the following:
$(document).ready(function() { $('#UserRenewWindow').jqxWindow({ maxHeight: 280, maxWidth: 430, minHeight: 250, minWidth: 350, height: 280, width: 600, showCloseButton: true, theme: 'ui-redmond' }); $('#UserRenewWindow').jqxWindow({position: {x: 600, y: 340}}); $('#UserRenewWindow').bind('closed', function() { // Some code here. $('div').remove('#UserRenewWindow'); }); $('#UserRenewButton').jqxButton({width: 80, height: 30, theme: 'ui-redmond'}); $('#UserRenewButton').val($.i18n('UserRenewButton')); if ($('#idUsu').val() !== '') { $('#idUsuR').val($('#idUsu').val()); } $('#UserRenewForm').jqxValidator({ rules: [ {input: '#idEmailR', message: 'El correo ha de ser válido',action:'keyup, blur',rule:'email'} ], theme: 'ui-redmond' }); $("#UserRenewButton").bind('click', function() { validateRenew(); }); function validateRenew() { if ($('#idEmailR').val() === '' && $('#idUsuR').val() === '') { var msg = "Debe rellenar uno de los dos campos."; $('#error', '#UserRenewForm').text(msg); } else { var comprueba; if ($('#idEmailR').val() !== '') { alert("A que te lo mando al mail..."); comprueba = $('#UserRenewForm').jqxValidator('validate'); alert(comprueba); $('#UserRenewWindow').jqxWindow('close'); } else { alert("A que te mando un mail..."); $('#UserRenewWindow').jqxWindow('close'); } } }});
I only need to validate de #idEmailR input if it contains data and check if is correct, do something .
Now, this code returns always false..
Can anybody see whats wrong??Hi,
In your scenario, you should write a custom validation rule. See: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxvalidator/defaultfunctionality.htm?web and especially how the validation of the Date is implemented through a custom validation rule.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.com/Hello dear Peter.
I don’t understand why you suggest me Date validation when i’m trying to validate an e-mail?.
I don’t understand why this line return false $(‘#UserRenewForm’).jqxValidator(‘validate’);
I’ve tried this too : $(‘#UserRenewForm’).jqxValidator(‘validateInput’, ‘#idEmailR’); and return false when i put my e-mail correctly and I don’t know why.I’ve tried customs validations, but always return false previous lines.
I have another question. It’s necessary rules for all the inputs of the form to validate the entire form? or only try to validate the inputs where I put rules to validate?
Thanks for your help.
David
As you suggested me, I’ve tryied the custom validation, but I can’t implements my idea. I’ve found my last attempt.
Look at this:{input: '#idEmailR', message: 'El correo ha de ser válido',action:'keyup',rule:function (input, commit) { if(input.val()!==''){ //some code }else{ if($('#usarR').val()!==''){ return true; }else{ return false; } } }
at //some code, I don’t know how, I need to validate e-mail, can you tell me if there is something like:
$(‘#UserRenewForm’).jqxValidator(‘validateInput’, ‘#idEmailR’, rule:’email’); to put there?best regards
-
AuthorPosts
You must be logged in to reply to this topic.