Greg Hinch![]()
The Form module allows for the programmatic creation of form and form field nodes. The available field nodes are TextField, HiddenField, CheckboxField, SelectField, ChoiceField, TextAreaField, and Buttons (a much less robust version than YUI 2's Button module). Fields can be manually instantiated and added to your Form, or configuration parameters may be passed directly when creating the Form and it will generate your Fields for you. There is also limited HTML parsing ability to pull in your Form data, but it is not yet fully baked.
This shows how you can create a Field object manually, and then use it while creating a form that also contains a number of Fields to be generated based on the supplied configuration parameters.
<script src="http://yui.yahooapis.com/3.6.0pr1/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2011.11.10-16-24'
}).use("gallery-form", function (Y) {
// Create a Field Object manually
var myField = new Y.CheckboxField({
name : "myCheckbox",
value : "check",
label : "Test Checkbox"
});
var f = new Y.Form({
boundingBox: '#form',
action : 'test.php',
method : 'post',
children : [
myField,
// Have the Form class create your fields itself
{name : "testText", required : true, label : "Test Label"},
{name : 'testHiddenField', type : "HiddenField"},
{name : 'testSelectField', type : 'SelectField', choices : [{label : 'Foo', value : 'foo'}, {label : 'Bar', value : 'bar'}], label : 'testSelect'},
{name : 'submitBtn', type : 'SubmitButton', value : 'Submit'},
{name : 'resetBtn', type : 'ResetButton', value : 'Reset'}
]
});
f.subscribe('success', function (args) {
alert ('Form submission successful');
});
f.subscribe('failure', function (args) {
alert('Form submission failed');
});
f.render();
});
| Subject | Author | Date |
|---|---|---|
| Which validators built in? | Greg Hinch | 11/2/09 |
| Re: Which validators built in? | Dav Glass | 11/3/09 |
| Re: Which validators built in? | Viktor Rennert | 11/3/09 |
| Field events | Eike Hirsch | 11/8/09 |
| Re: Field events | Greg Hinch | 11/10/09 |
| Re: Field events | Eike Hirsch | 11/11/09 |
| New Version Available | Greg Hinch | 11/15/09 |
| multipart / file field | Raphaël Bauduin | 12/15/09 |
| Suggestions: my wishlist | Satyam | 12/18/09 |
| Re: Suggestions: my wishlist | Joe Developer | 01/4/10 |
© 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