Foros de discusión
How to "DISABLE" the validator after bound to a field?
bo li, modificado hace 11 años.
How to "DISABLE" the validator after bound to a field?
Junior Member Mensajes: 38 Fecha de incorporación: 14/11/11 Mensajes recientes
A question about AUI form and AUI validator. Q: How to "DISABLE" the validator after bound to a field?
Context:
When the form loads, there is a selection box of option1 option2, option3, and hidden fields field1, field2, field3.
1.Select "option1", input field "field1" will show up, and bound with A.FormValidator( required:true).
2.Select "option2", input field "field1" will be hidden, "field2" will show up.
At this point, I set the validator for "field1" required:false. But it is still required.
I think the form can't be sent to the server to change required:false. Is there a solution for this? Thanks in advance!
Context:
When the form loads, there is a selection box of option1 option2, option3, and hidden fields field1, field2, field3.
1.Select "option1", input field "field1" will show up, and bound with A.FormValidator( required:true).
2.Select "option2", input field "field1" will be hidden, "field2" will show up.
At this point, I set the validator for "field1" required:false. But it is still required.
I think the form can't be sent to the server to change required:false. Is there a solution for this? Thanks in advance!
Pavel Savinov, modificado hace 11 años.
RE: How to "DISABLE" the validator after bound to a field?
Junior Member Mensajes: 94 Fecha de incorporación: 24/09/12 Mensajes recientes
Hi!
Here some kind of working solution of that problem, but i'm sure that there should be something more elegant:
Here some kind of working solution of that problem, but i'm sure that there should be something more elegant:
<form id="someForm">
<input type="text" name="someField" id="someField2">
<button type="submit" value="submit"></button>
<button type="button" onclick="cancelValidation('someField2');" value="no-validation"></button>
</form>
<aui:script>
function cancelValidation(fieldId) {
AUI().ready('aui-form-validator',
function (A) {
var v = A.one("#someForm").validatorObject;
v.on("validateField", function (event) {
for (var k in event.details) {
var name = event.details[k].validator.field;
if (name.lastIndexOf("#" + fieldId) != -1) {
event.halt();
break;
}
}
});
});
}
AUI().ready('aui-form-validator',
function (A) {
var v = new A.FormValidator({
boundingBox : '#someForm',
rules : {
someField : {
required : true
}
}
});
A.one("#someForm").validatorObject = v;
});
</aui:script>
bo li, modificado hace 11 años.
RE: How to "DISABLE" the validator after bound to a field?
Junior Member Mensajes: 38 Fecha de incorporación: 14/11/11 Mensajes recientes
Thank you for your solution, I am using the similar way to do it, event.hault() to prevent the event from happening.
Alexey Kakunin, modificado hace 8 años.
RE: How to "DISABLE" the validator after bound to a field?
Liferay Master Mensajes: 621 Fecha de incorporación: 7/07/08 Mensajes recientes
Hi Pavel!
Thank you for your suggestions (it's really helped me!) - only small correction (for anybody who will try to use it for 6.2):
in Liferay 6.2.x it is required to use
to get name of processed field.
====
Alexey Kakunin
Liferay Experts in Russia
Thank you for your suggestions (it's really helped me!) - only small correction (for anybody who will try to use it for 6.2):
in Liferay 6.2.x it is required to use
var name = event.details[k].validator.field.get('name');
to get name of processed field.
====
Alexey Kakunin
Liferay Experts in Russia