Modal: Difference between revisions
Appearance
Created page with "== Introduction == Modals are popup windows that let users input information into a form. thumb|A URL modal == API == === Constructor === <syntaxhighlight lang="javascript"> let modal = new Modal(); </syntaxhighlight> === Functions === modal.createForm() modal.submitForm() modal.cancelForm() modal.alignForm() modal.unalignForm() modal.addEntry(label, type, validation) modal.setSize(width, height) modal.setMinimumSize(width, height) modal..." |
Fix Modal documentation error (getTabData) |
||
| (9 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{Page in progress}} | |||
== Introduction == | == Introduction == | ||
Modals are popup windows that let users input information into a form. | Modals are popup windows that let users input information into a form. | ||
| Line 11: | Line 13: | ||
=== Functions === | === Functions === | ||
modal.submitForm() | ==== modal.createForm(): <code>void</code> ==== | ||
Creates a form section in the modal. | |||
Modals are currently limited to one form only. | |||
==== modal.submitForm(): <code>void</code> ==== | |||
Validates, processes, and submits the form. | |||
This triggers the onSubmit callback. | |||
==== modal.cancelForm(): <code>void</code> ==== | |||
Revert the form and close the modal. | |||
==== modal.alignForm(): <code>void</code> ==== | |||
Line up all form labels. | |||
The form labels are set to the left and the inputs are set to the right. | |||
==== modal.unalignForm(): <code>void</code> ==== | |||
Set each form label on its own line. | |||
==== modal.addEntry(label: <code>String</code>, type?: <code>"text" | "color"</code>, validation?: <code>"number" | "required"</code>): <code>EntryObj</code> ==== | |||
Add an input entry to the form. | |||
label: The label to be shown next to the input. | |||
type (optional): 'text' or 'color'. The type of input. | |||
validation (optional): 'number' or 'required'. Check if the entry contains a valid value. | |||
==== modal.setSize(width: <code>Number</code>, height: <code>Number</code>): <code>void</code> ==== | |||
Sets the fixed size of the modal. | |||
Any overflown content will be hidden. | |||
Setting either dimension to zero will reset that dimension. | |||
modal. | ==== modal.setMinimumSize(width: <code>Number</code>, height: <code>Number</code>): <code>void</code> ==== | ||
Sets the minimum size of the modal. | |||
modal. | The modal cannot be smaller than this size. | ||
Setting either dimension to zero will reset that dimension. | |||
modal. | ==== modal.setMaximumSize(width: <code>Number</code>, height: <code>Number</code>): <code>void</code> ==== | ||
Sets the maximum size of the modal. | |||
modal. | The modal cannot be bigger than this size. Overflown content will be hidden. | ||
Setting either dimension to zero will reset that dimension. | |||
modal. | ==== modal.setFormTitle(title: <code>String</code>, opts?: <code>{ bold?: Boolean, center?: Boolean }</code>): <code>void</code> ==== | ||
Set a title or description at the top of the modal. | |||
modal. | ==== modal.setFooter(): <code>void</code> ==== | ||
Add a footer to the bottom of the modal. | |||
The footer is split into three parts (left, center, right). | |||
modal.removeFooter() | ==== modal.removeFooter(): <code>void</code> ==== | ||
Removes the footer from the modal. | |||
modal.setFooterCheckbox(labelName, callback, defaultState) | ==== modal.setFooterCheckbox(labelName: <code>String</code>, callback: <code>Function<any></code>, defaultState: <code>Boolean</code>): <code>void</code> ==== | ||
Adds a checkbox to the left section of the footer. | |||
labelName: name of the checkbox. | |||
callback: to be called when the checkbox is checked (parameter: checked) | |||
modal. | ==== modal.setFooterContentLeft(data: <code>HTMLElement</code>): <code>void</code> ==== | ||
Adds content to a section of the footer. | |||
modal. | ==== modal.setFooterContentCenter(data: <code>HTMLElement</code>): <code>void</code> ==== | ||
Adds content to a section of the footer. | |||
modal. | ==== modal.setFooterContentRight(data: <code>HTMLElement</code>): <code>void</code> ==== | ||
Adds content to a section of the footer. | |||
modal. | ==== modal.removeFooterContentLeft(): <code>void</code> ==== | ||
Clears a section of the footer. | |||
modal. | ==== modal.removeFooterContentCenter(): <code>void</code> ==== | ||
Clears a section of the footer. | |||
modal. | ==== modal.removeFooterContentRight(): <code>void</code> ==== | ||
Clears a section of the footer. | |||
modal. | ==== modal.onSubmit(callback: <code>Function<any></code>): <code>void</code> ==== | ||
Set event callback. | |||
This will be called whenever the form is submitted. | |||
modal. | ==== modal.onOpen(callback: <code>Function<any></code>): <code>void</code> ==== | ||
Set event callback. | |||
This will be called whenever the form is opened. | |||
modal. | ==== modal.onClose(callback: <code>Function<any></code>): <code>void</code> ==== | ||
Set event callback. | |||
This will be called whenever the form is closed. | |||
modal. | ==== modal.onTabChange(callback: <code>Function<any></code>): <code>void</code> ==== | ||
Set event callback. | |||
This will be called whenever the tab is changed. | |||
modal. | ==== modal.checkboxFieldOnInput(callback: <code>Function<any></code>): <code>void</code> ==== | ||
Set event callback. | |||
This will be called whenever a checkbox is checked or unchecked. | |||
modal. | ==== modal.open(...params?: <code>any</code>): <code>void</code> ==== | ||
Display the modal. | |||
All parameters will be passed to the onOpen event. | |||
modal. | ==== modal.close(canceled?: <code>Boolean</code>): <code>void</code> ==== | ||
Hide the modal. | |||
modal. | canceled: This modal has closed as a result of form cancelation. This will revert the values of the form inputs. | ||
modal.createClose() | ==== modal.createCheckboxField(): <code>void</code> ==== | ||
Add a checkbox section to the modal. | |||
The checkbox section contains a nestable list of checkbox inputs. | |||
Only one checkbox field is currently supported. | |||
==== modal.addCheckbox(label: <code>String</code>, parent?: <code>CheckboxObj</code>): <code>CheckboxObj</code> ==== | |||
Adds a checkbox to the checkbox field. | |||
label: The name of the checkbox. | |||
parent (optional): The parent checkbox. Nested checkboxes will be indented. | |||
==== modal.addTab(id: <code>Number</code>, title: <code>String</code>): <code>void</code> ==== | |||
Insert a new tab to the modal along with a new client area. | |||
If no tab exists, the current client area becomes part of the first tab. | |||
==== modal.focusTab(id: <code>Number</code>): <code>void</code> ==== | |||
Make the tab the current visible tab. | |||
==== modal.getCurrentTabId(): <code>Number | null</code> ==== | |||
If there are any defined tabs, return the ID of the currently active tab. | |||
==== modal.hideTab(id: <code>Number</code>): <code>void</code> ==== | |||
Hide tab from the tab bar. This will not bring you to the next available tab. | |||
==== modal.showTab(id: <code>Number</code>): <code>void</code> ==== | |||
Show tab on the tab bar. | |||
==== modal.getTabData(id: <code>Number</code>): <code>TabContext | null</code> ==== | |||
Return raw tab data. | |||
==== modal.append(elm: <code>HTMLElement</code>): <code>void</code> ==== | |||
Insert content to the modal. | |||
==== modal.createClose(): <code>void</code> ==== | |||
Adds a close caption to the bottom right of the modal. | |||
=== Interfaces === | |||
==== CheckboxObj ==== | |||
<syntaxhighlight lang="typescript"> | |||
Object { | |||
elm: HTMLLabelElement, | |||
cbElm: Function, | |||
children: Array<CheckboxObj> | |||
} | |||
</syntaxhighlight> | |||
==== EntryObj ==== | |||
<syntaxhighlight lang="typescript"> | |||
Object { | |||
input: HTMLInputElement | |||
} | |||
</syntaxhighlight> | |||
==== FormInputObj ==== | |||
<syntaxhighlight lang="typescript"> | |||
Object { | |||
input: HTMLInputElement, | |||
value: String, | |||
validation: "number" | "required", | |||
validationFailed: Boolean, | |||
type: "text" | "color", | |||
label: HTMLLabelElement | |||
} | |||
</syntaxhighlight> | |||
==== TabContext ==== | |||
<syntaxhighlight lang="typescript"> | |||
Object { | |||
id: Number, | |||
tabButton: HTMLElement, | |||
client: HTMLElement, | |||
inputField: HTMLElement, | |||
formTitle: HTMLElement, | |||
formField: HTMLElement, | |||
formInputs: Array<FormInputObj>, | |||
hasSubmitted: Boolean, | |||
cbField: HTMLElement, | |||
cbList: Array<CheckboxObj>, | |||
cbCallback: Function<any> | |||
} | |||
</syntaxhighlight> | |||
=== Static functions === | === Static functions === | ||
Modal.closeAll() | |||
==== Modal.closeAll(): <code>void</code> ==== | |||
Close all opened modals. | |||
=== Static variables === | === Static variables === | ||
Modal. | ==== Modal.isOpen: <code>Boolean</code> ==== | ||
Stores whether or not a modal is opened. | |||
Modal.list | ==== Modal.current: <code>Modal | null</code> ==== | ||
Stores the instance of the currently open modal. | |||
==== Modal.list: <code>Array<Modal></code> ==== | |||
Stores a list of all instantiated modals. | |||
=== Examples === | |||
Create an announcement<syntaxhighlight lang="javascript" line="1"> | |||
let modal = new Modal(); | |||
modal.createForm(); | |||
modal.setFormTitle("Create an announcement\n"); | |||
let announcementText = modal.addEntry("Text", "text").input; | |||
modal.setMaximumSize(360, 300); | |||
modal.onSubmit(function() { | |||
w.doAnnounce(announcementText.value); | |||
}); | |||
modal.open(); | |||
</syntaxhighlight> | |||
[[Category:Documentation]] | |||