forked from vitmalina/w2ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved toggleGroup to honor the value of show. execute el.next() only once added docs and demos for toggleGroup and field.html.groupCollapsible
- Loading branch information
Showing
4 changed files
with
231 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<div class="content"> | ||
<div id="example_title"> | ||
<h1>Collapsible Groups</h1> | ||
Groups can be collapsed, expanded, and toggled. | ||
</div> | ||
<div id="example_view"></div> | ||
<div id="example_code"></div> | ||
</div> | ||
|
||
<!--CODE--> | ||
<div id="form" style="width: 750px; height: 500px"></div> | ||
<br> | ||
<button class="w2ui-btn" onclick="w2ui.form.toggleGroup('General')">Toggle General</button> | ||
<button class="w2ui-btn" onclick="w2ui.form.toggleGroup('Address Group 2')">Toggle Address Group 2</button> | ||
<button class="w2ui-btn" onclick="w2ui.form.toggleGroup('Address Group 3', false)">Collapse Address Group 3</button> | ||
<button class="w2ui-btn" onclick="w2ui.form.toggleGroup('Address Group 3', true)">Expand Address Group 3</button> | ||
<br> | ||
|
||
<!--CODE--> | ||
<script> | ||
$(function () { | ||
$('#form').w2form({ | ||
name : 'form', | ||
url : 'server/post', | ||
fields : [ | ||
{ field: 'first_name', type: 'text', | ||
html: { | ||
group: 'General', | ||
groupCollapsible: true, | ||
page: 0, | ||
column: 0, | ||
label: 'First Name', | ||
span: 4 | ||
} | ||
}, | ||
{ field: 'last_name', type: 'text', | ||
html: { | ||
page: 0, | ||
column: 0, | ||
label: 'Last Name', | ||
span: 4 | ||
} | ||
}, | ||
{ field: 'middle_name', type: 'text', | ||
html: { | ||
page: 0, | ||
column: 0, | ||
label: 'Middle Name', | ||
span: 4 | ||
} | ||
}, | ||
{ field: 'Other', type: 'textarea', | ||
html: { | ||
page: 0, | ||
column: 1, | ||
group: 'Additional Info', | ||
groupCollapsible: true, | ||
groupStyle: 'min-height: 115px', | ||
label: 'Other', | ||
span: -1, | ||
attr: 'style="width: 100%; resize: vertical"' | ||
} | ||
}, | ||
{ field: 'address1', type: 'text', | ||
html: { | ||
page: 0, | ||
column: 0, | ||
group: 'Address Group 1', | ||
groupCollapsible: false, | ||
label: 'Address', | ||
} | ||
}, | ||
{ field: 'address2', type: 'text', | ||
html: { | ||
page: 0, | ||
label: 'Line 2', | ||
column: 0 | ||
} | ||
}, | ||
{ field: 'city', type: 'text', | ||
html: { | ||
page: 0, | ||
group: 'Address Group 2', | ||
groupCollapsible: true, | ||
groupStyle: 'height: 170px', | ||
label: 'City', | ||
column: 1, | ||
} | ||
}, | ||
{ field: 'state', type: 'text', | ||
html: { | ||
page: 0, | ||
label: 'State', | ||
column: 1 | ||
} | ||
}, | ||
{ field: 'zip', type: 'int', | ||
html: { | ||
page: 0, | ||
label: 'Zip', | ||
column: 1 | ||
} | ||
}, | ||
{ field: 'country', type: 'text', | ||
html: { | ||
page: 0, | ||
group: 'Address Group 3', | ||
groupCollapsible: true, | ||
label: 'Country', | ||
column: 0, | ||
} | ||
} | ||
], | ||
actions: { | ||
Reset: function () { | ||
this.clear(); | ||
}, | ||
Save: function () { | ||
if (w2ui.form.validate().length == 0) { | ||
w2popup.open({ | ||
title: 'Form Data', | ||
with: 600, | ||
height: 550, | ||
body: `<pre>${JSON.stringify(this.getCleanRecord(), null, 4)}</pre>`, | ||
buttons: '<button class="w2ui-btn" onclick="w2popup.close()">Ok</button>' | ||
}) | ||
} | ||
}, | ||
custom: { | ||
text: '<span style="font-size: 16px">←</span> click to see data', | ||
class: 'custom-class', | ||
style: 'background-image: none; background-color: transparent; border: 0px; margin: 0 0 0 -10px;', | ||
onClick() { | ||
w2alert('Not me!! The other button') | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Toggles the collapsed state of a form's group. | ||
|
||
<div class="definition"> | ||
toggleGroup(groupName, [show]) | ||
</div> | ||
|
||
<div class="arguments"> | ||
<table> | ||
<tr> | ||
<td>groupName</td> | ||
<td><b>string</b>, name of the group</td> | ||
</tr> | ||
<tr> | ||
<td>show</td> | ||
<td><b>boolean</b>, if true the group will be expanded, if false the group will be collapsed <i>(optional)</i></td> | ||
</tr> | ||
</table> | ||
</div> | ||
|
||
Returns <i>undefined</i>. | ||
|
||
<h4>Description</h4> | ||
|
||
This method will toggle the collapsed/expanded state of a group if <span class="argument">show</span> is not set. | ||
<div style="height: 10px"></div> | ||
|
||
If <span class="argument">show</span> is, the group will be collapsed/expanded based on the value of <span class="argument">show</span>. | ||
<div style="height: 10px"></div> | ||
|
||
|
||
If you have form defined in the following way: | ||
<textarea class="javascript"> | ||
$('#form').w2form({ | ||
name : 'form', | ||
url : 'server/post', | ||
fields: [ | ||
{ field: 'first_name', type: 'text', | ||
html: { | ||
group: 'General', | ||
groupCollapsible: true, | ||
page: 0, | ||
column: 0, | ||
label: 'First Name', | ||
span: 4 | ||
} | ||
}, | ||
{ field: 'last_name', type: 'text', | ||
html: { | ||
page: 0, | ||
column: 0, | ||
label: 'Last Name', | ||
span: 4 | ||
} | ||
}, | ||
{ field: 'middle_name', type: 'text', | ||
html: { | ||
page: 0, | ||
column: 0, | ||
label: 'Middle Name', | ||
span: 4 | ||
} | ||
} | ||
] | ||
}); | ||
</textarea> | ||
|
||
You can do: | ||
<textarea class="javascript"> | ||
// toggle collapsed/expanded state of the group based on the current state | ||
w2ui.form.toggleGroup('General'); | ||
// collapse the group | ||
w2ui.form.toggleGroup('General', false); | ||
// expand the group | ||
w2ui.form.toggleGroup('General', true); | ||
</textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters