This support forum belongs to the Form Validator Gallery Module.
Form Validator has a bug tracker here: http://github.com/murdog05/yui3-gallery/issues
| Page 1 of 2 | [ 16 posts ] | Go to page 1, 2 Next |
|
Hi All,
I was wondering if anyone knew how I could do dynamic forms using this form validation. From what I see you have to create the form before calling the javascript initialisation, and once created the form cannot change. Is this correct? Is there any way I can add form fields dynamically and then add them to the form validation object after creation? Thanks, James |
Alberto SantiniYUI Contributor
|
Hello James.
I have not been using this module, but I was wondering if you tried to add the fields with addInput API [1]. Regards, Alberto [1] http://murdog05.github.com/yui3-gallery ... dator.html |
|
Yes,
Alberto is correct, you can use the addInput function. for example myForm.addInput(new validator.TextBaseField({inputDOM:'domId'})); If this doesn't work, let me know and I will see if I can do up an example for you. |
|
Hi All,
Yes that works fine. I was also wondering, is there any way I can apply styles to the inputs instead of adding in another element into the dom. I'd like to highlight the inputs by making them red/green and also changing their border colour. I understand if this isn't the way the validator works (It doesn't seem to) but I think it would be a handy feature to add into a future release. Also when you call addInput you have to call checkFormValues after otherwise the field is labelled as valid. Is this an error? It looks like both the elements that are added in after the input at both visible, and none is set as hidden. |
|
Hi again.
I was wonder if I can set certain input/selects/buttons as disabled based on the value of other input/selects. I have a select list that contains "Contains, Not contain, Equal to, Not Equal, Is Empty, Not Empty" and a value field that the user can fill in, but only if the user hasn't selected "Is Empty" or "Not Empty". I want to have the value field disabled if the user selects either "Is Empty" or "Not Empty" I also want to disable a button in the form unless two text areas are filled in. Sorry for all the question! Adios, James |
|
Hi James,
As for your first question, yes it is possible to apply CSS to the input field. See this example http://murdog05.github.com/yui3-gallery ... ample.html As for the checkFormValues, you have to call that after you add your input for efficiency. If you were adding more than 1, say 10 fields, then you wouldn't want checkFormValues called 10 times, you would just want to do it once after you have added all 10 fields. As for the your last question, regarding setting input/select/buttons as disabled based on the value of other input/selects, you have two options. The Custom Input Field might work for you http://murdog05.github.com/yui3-gallery ... stom_input OR, (and I recommend this one) Subscribe to the onchange event of the field who's value will determine whether the input is disabled http://murdog05.github.com/yui3-gallery ... t_onchange Subscribing to the onchange event will allow you to check the value of the field that has changed (along with the current values of any other fields) and determine whether or not to enable/disable a field/button. I hope you find this helpful, let me know if you need anymore help. Murray |
|
OK, I know I'm being stupid....
How do I subscribe to the onchange event of one of my added inputs... I've tried... var id_field = new Y.IntegerField({ inputDOM:'ttm_page_id_'+ttm_count, emptyValue:'none', incorrectCss:'invalid', correctCss:'valid' }); ttm_pages_form.addInput(id_field); // TIRED ALL OF THESE //id_field.onchange(testfunction); //id_field.on('change', testfunction); //id_field.on('onchange', testfunction); //Y.Event.attach('onchange',function(){alert('hello world');},'#ttm_page_id_'+ttm_count); //id_field.attach('onchange',function(){alert('hello world');},'#ttm_page_id_'+ttm_count); function testfunction(e) { alert('hello world'); } |
|
Got it....
Y.Event.attach('change',function(){alert('hello world');}, '#ttm_page_id_'+ttm_count); I'm assuming that this won't affect the validation? I will also need to bind to keyup and keydown to make sure I do it instantly. |
|
OK, so next thing I'm trying to do is create a custom field.
I currently have some inputs that need to validate themselves (text/number) and then make sure that there is no other matching field in the form with the same value. e.g. [PATH_1] [ID_1] [PARSE_1] [OPTIONS (DIV WITH SOME SELECTS IN)] [PATH_2] [ID_2] [PARSE_2] [OPTIONS (DIV WITH SOME SELECTS IN)] [PATH_3] [ID_3] [PARSE_3] [OPTIONS (DIV WITH SOME SELECTS IN)] The validator needs to work as follows. All the PATH elements have to be text & no other PATH element can have the same value All the ID elements must be a number & no other ID element can have the same value All the PARSE & OPTIONS elements are only active if the matching PATH and ID elements are valid I started with the following pseudo code var ttm_pages_form = new Y.Validator({form:'ttm_pages'}); for(var i = 0; i<3; i++) { // ADD IN FIELD // [CODE TO ADD IN FIELD TO FORM] // Add in validator to field ttm_pages_form.addInput(new Y.CustomField({ inputDOM:'ttm_page_id_'+i, validatorObject:IDPathCombo })); ttm_pages_form.addInput(new Y.CustomField({ inputDOM:'ttm_page_path_'+i, validatorObject:IDPathCombo })); } And the following Object var IDPathCombo = { isValid:function() { // Check if this field is a path or id by extracting the correct bit from the ID // I understand how to do this.... // If it's a path check it's a valid TextBaseField //???? Not sure how to do this pathValid = Y.TextBaseField.isValid.call(this); //???? // If it's an ID check it's a valid IntegerField //???? Not sure how to do this intValid = Y.IntegerField.isValid.call(this) //???? // As long as it's a valid field check if any other matching fields have the same valid // I understand how to do is because I can grab all INPUTS with a matching ID part // and then get it's value and compare to the curent value // If all pass return true return true; } }; Then I bind to the change, keyup, keydown functions of the ID and PATH elements and call a function to check if they pass their isValid function. If they do then it will disable the PARSE and OPTIONS elements. I understand how to do this. What I'm not sure about is the isValid function. In isValid it doesn't seem to pass anything in, or set this is another context. I'm sorry I'm being such an idiot, but I'm not really that good with this whole YUI/JS thing! |
|
I've also been testing with a group based field, but can't get that to work either.
I was thinking that if I put the PATH and ID elements into groups that I can check if the group is valid and enable the parse button that way. Only problem would be that if I don't have the PATH and ID elements as a custom field I don't think I'd be able to test if any of the other PATH or ID elements had the same value. Anyways, here is the half baked code I tried var path_field = new Y.TextBaseField({ inputDOM:'ttm_page_path_'+ttm_count, emptyValue:'none', incorrectCss:'invalid', correctCss:'valid' }); var id_field = new Y.IntegerField({ inputDOM:'ttm_page_id_'+ttm_count, emptyValue:'none', incorrectCss:'invalid', correctCss:'valid' }); ttm_pages_form.addInput(new Y.GroupBaseField({ //groupDOM:'ttm_idpath_combo_'+ttm_count, membersJSON:[path_field,id_field], minValid:2 })); |
| Page 1 of 2 | [ 16 posts ] | Go to page 1, 2 Next |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group