This support forum belongs to the Form Gallery Module.
Form has a bug tracker here: https://github.com/ghinch/yui-gallery-form/issues
| Page 1 of 2 | [ 12 posts ] | Go to page 1, 2 Next |
|
Hi,
I'm not a YUI or javascript expert, but I would really like to use Form to help me validate form fields. I have a simple mortgage calculator with three input fields (loan_amount, interest_rate, loan_term) and I don't need to submit the form, just detect a click on a Calculate button, perform, the calculation and show the result in a read-only field. However, I do need to validate the 3 input fields before I perform the calculation. At the moment, it looks like validation is performed when the submit event is detected. Since I have my form set up with onsubmit="return(false);", can I configure form to use another event? TIA, Nick |
Alberto SantiniYUI Contributor
|
Hello nickweavers.
It may help the validator attribute. Did you give a look at form examples: http://www.greghinch.com/examples/form/ Hope that helps, IceBox |
|
Hi Alberto,
Yes I looked at the examples but didn't see anything there on how to either use another event. Nick |
Alberto SantiniYUI Contributor
|
Hello Nick.
Maybe I misunderstood the use case. In the examples the validation is done before the submit using validator. Is it not your case? Regards, Alberto |
|
It may make sense to use inline validation:
http://www.greghinch.com/yui3-gallery/docs/Form.html#config_inlineValidation Setting this to true in your form will validate that individual field as soon as it is changed by the user. You can also set "validateInline" to true on individual fields to just do that on specific ones and not the whole form. Finally, you can call "validateField()" on any field at any time to do the validation when it makes sense for you, but you'll have to define when that is specifically for you application. Hope that helps! |
|
Hi Alberto,
I think it was me who misunderstood the order of things. Thanks for making it clearer. Nick |
|
Hi Greg,
Right, inline validation would work nicely I think. The bit that confuses me in the code that is generated is that in my markup I have a button like this <button id="repayment_calculator_submit" type="submit">Calculate</button> but after calling myForm.render(); it changes to this <button id="repayment_calculator_submit-field" class="field">Calculate</button> The problem for me is that I have an event listener for the onSubmit that looks like this function calculateMortgageRepayment(e) { e.preventDefault(); ... // Use form field contents to do calculation and show result ... } So this now isn't called and my Calculate button doesn't work. How should I get around this? Thanks, Nick |
Alberto SantiniYUI Contributor
|
Hello Nick.
I think you should set to false the attribute (not documented) submitViaIO and define (override) the submit function with the content of the calculateMortgageRepayment function. See the working example: http://jsfiddle.net/HHEMZ/ Hope that helps, Alberto P.S.: Greg, I am sorry if I have been overlapping this thread. I hope my suggestion is correct. P.S.: Nick, and you should remove onsubmit. |
|
Thanks for all your help Alberto.
I have tried to replicate the essential parts of what you had in the jsfiddle example, but even with "submitViaIO: false" in the form config and the repayment_calculator.get('srcNode').submit = function () { alert('Pressed submit'); .... } I am seeing the form get submitted and the alert does not show. You can see the page with the form on here: https://www.chimneypotsonline.co.uk/ind ... owFormPage (I'm only working on the lower form at the moment, there are two forms on the page.) I must have overlooked something so I'll keep staring at the code. Nick |
Alberto SantiniYUI Contributor
|
Hello Nick.
In that page there is an error in yui_calculate_mortgage_repayment.js (line27): Uncaught ReferenceError: myForm is not defined. I think you should use repayment_calculator. And in submit function there is the line "e.preventDefault();": "e" is not defined. Hope that helps, Alberto |
| Page 1 of 2 | [ 12 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