OOUI/Layouts/Forms
OOUI |
---|
Introduction |
Getting started |
Working with widgets |
See also |
v · d · e |
FormLayout
s are used to wrap FieldsetLayouts when you intend to use browser-based form submission for the fields, rather than handling them in JavaScript. Only widgets from the InputWidget family support form submission. Input widgets include standard form elements like checkboxes, radio buttons and text fields, as well as some fancier controls. Some controls have both regular and input variants, for example, DropdownWidget and DropdownInputWidget – only the latter support form submission and often have simplified APIs to match the capabilities of HTML forms.
The following example illustrates a simple login form:
<!-- This example illustrates a FormLayout that contains a FieldsetLayout (which in turn contains FieldLayouts for the text input fields and input button). --> <style> body{ font-family:sans-serif; font-size:0.875em; } .container{ width:500px; height:230px; border:1pxdotted#c8ccd1; padding:16px; } </style> <script> // Create form elements (two text inputs and the button input, in this example). varinput1=newOO.ui.TextInputWidget({ value:'username' }), input2=newOO.ui.TextInputWidget({ value:'password', type:'password' }), submit=newOO.ui.ButtonInputWidget({ label:'Login', flags:[ 'primary', 'progressive' ] }), // Create a FieldsetLayout. fieldset=newOO.ui.FieldsetLayout({ label:'Login form layout with a fieldset layout', classes:['container'] }); // Use the addItems() method to add FieldLayouts that contain the form // elements (the text inputs and submit button) to the FieldsetLayout: fieldset.addItems([ newOO.ui.FieldLayout(input1,{ label:'Username', align:'top' }), newOO.ui.FieldLayout(input2,{ label:'Password', align:'top' }), newOO.ui.FieldLayout(submit) ]); // Add the FieldsetLayout to a FormLayout. varform=newOO.ui.FormLayout({ items:[fieldset], action:'/api/formhandler', method:'get' }); $(document.body).append(form.$element); </script>
Form layouts can be configured with an HTML form action, an encoding type, and a method using the action
, enctype
, and method
configs, respectively.
For a full list of supported methods and configuration options, please see the code-level documentation.
Get help:
- #wikimedia-editing connect ← Live chat (IRC)
- wikitech-l ← Mailing list
- Talk:OOUI ← Talk page
- ooui (add task ) ← Phabricator project page