Browse Source

Add many new form validation updates

avalanche1-patch-2
Jack Lukic 9 years ago
parent
commit
15a105ca9b
  1. 197
      server/documents/behaviors/form.html.eco
  2. 3
      server/documents/elements/icon.html.eco
  3. 10
      server/documents/elements/label.html.eco
  4. 63
      server/documents/hotfix.html.eco
  5. 64
      server/files/javascript/validate-form.js

197
server/documents/behaviors/form.html.eco

@ -24,18 +24,33 @@ type : 'UI Behavior'
<h2 class="ui dividing header">Usage</h2>
<div class="example">
<h4 class="ui header">Setting-up Fields</h4>
<div class="auto example">
<h4 class="ui header">Specifying Validation Rules</h4>
<p>Form validation requires passing in a validation object with the rules required to validate your form.</p>
<div class="ui ignored info message">
A validation object includes a list of form elements, and rules to validate each against. Fields are matched by either the <code>id</code> tag, <code>name</code> tag, or the <code>data-validate</code> metadata matching the identifier provided in the settings object.
A validation object includes a list of form elements, and rules to validate each field against. Fields are matched by either the <code>id</code>, <code>name</code>, or <code>data-validate</code> property matching the identifier specified in the settings object.
</div>
<div class="ignore code">
<div class="ignore code" data-title="Shorthand">
$('.ui.form')
.form({
fields: {
name : 'empty',
gender : 'empty',
username : 'empty',
password : ['minLength[6]', 'empty'],
skills : ['minCount[2]', 'empty'],
terms : 'checked'
}
})
;
</div>
<div class="ui horizontal divider">or</div>
<div class="ignore code" data-title="Expanded Version">
$('.ui.form')
.form({
fields: {
name: {
identifier : 'name',
identifier: 'name',
rules: [
{
type : 'empty',
@ -44,7 +59,7 @@ type : 'UI Behavior'
]
},
skills: {
identifier : 'skills',
identifier: 'skills',
rules: [
{
type : 'minCount[2]',
@ -53,7 +68,7 @@ type : 'UI Behavior'
]
},
gender: {
identifier : 'gender',
identifier: 'gender',
rules: [
{
type : 'empty',
@ -62,7 +77,7 @@ type : 'UI Behavior'
]
},
username: {
identifier : 'username',
identifier: 'username',
rules: [
{
type : 'empty',
@ -71,7 +86,7 @@ type : 'UI Behavior'
]
},
password: {
identifier : 'password',
identifier: 'password',
rules: [
{
type : 'empty',
@ -79,12 +94,12 @@ type : 'UI Behavior'
},
{
type : 'minLength[6]',
prompt : 'Your password must be at least 6 characters'
prompt : 'Your password must be at least {ruleValue} characters'
}
]
},
terms: {
identifier : 'terms',
identifier: 'terms',
rules: [
{
type : 'checked',
@ -146,6 +161,102 @@ type : 'UI Behavior'
</div>
</form>
<div class="prompt example">
<h4 class="ui header">Customizing Prompts</h4>
<p>Form validation includes default error prompts for most cases, however these can be quite generic. To specify custom personalized values for a validation prompt use the <code>prompt</code> property with a rule.</p>
<div class="ui ignored info message">You can set default messages for each validation rule type by modifying <code>$fn.form.settings.prompt</code></div>
<p>Prompt also supports custom templating with the following values replaced</p>
<table class="ui celled sortable basic table segment">
<tbody>
<tr>
<td class="four wide"><b>{name}</b></td>
<td>The current text of a field's label, or if no label available its placeholder text</td>
</tr>
<tr>
<td class="four wide"><b>{identifier}</b></td>
<td>The identifier used to match the field</td>
</tr>
<tr>
<td class="four wide"><b>{value}</b></td>
<td>The current field value</td>
</tr>
<tr>
<td class="four wide"><b>{ruleValue}</b></td>
<td>The value passed to a rule, for example <code>minLength[100]</code> would set this value to 100</td>
</tr>
</tbody>
</table>
<div class="ignored code">
$('.ui.form')
.form({
fields: {
field1: {
rules: [
{
type : 'empty'
}
]
},
field2: {
rules: [
{
type : 'exactly[dog]',
prompt : '{name} is set to "{value}" that is totally wrong. It should be {ruleValue}'
}
]
}
}
})
;
</div>
<form class="ui form segment">
<div class="two fields">
<div class="field">
<label>Field 1</label>
<input type="text" name="field1">
</div>
<div class="field">
<label>Field 2</label>
<input type="text" name="field2">
</div>
</div>
<div class="ui blue submit button">Submit</div>
<div class="ui error message">
</div>
</form>
</div>
<div class="matching example">
<h4 class="ui header">Matching Fields</h4>
<p>By default the property name used in the validation object will match against the <code>id</code>, <code>name</code>, or <code>data-validate</code> property of each input to find the corresponding field to match validation rules against.</p>
<p>If you need to specify a different identifier you can use the <code>identifier</code> property on each validation rule</p>
<div class="ignored code">
$('.ui.form')
.form(
fields: {
name: {
identifier : 'special-name',
rules: [
{
type : 'empty'
}
]
}
}
})
;
</div>
<form class="ui form segment">
<div class="field">
<label>Special Field</label>
<input type="text" name="special-name">
</div>
<div class="ui blue submit button">Submit</div>
<div class="ui error message">
</div>
</form>
</div>
<h2 class="ui dividing header">Rules</h2>
<div class="no example">
@ -1539,7 +1650,7 @@ type : 'UI Behavior'
<table class="ui celled sortable definition table">
<thead>
<th>Setting</th>
<th class="four wide">Default</th>
<th class="six wide">Default</th>
<th>Description</th>
</thead>
<tbody>
@ -1583,6 +1694,68 @@ type : 'UI Behavior'
</tbody>
</table>
</div>
<div class="no example">
<h4 class="ui header">
Form Prompts
</h4>
<p>Settings to modify default form prompts</p>
<table class="ui celled sortable definition table">
<thead>
<th class="collapsing">Setting</th>
<th>Default</th>
</thead>
<tbody>
<tr>
<td>text</td>
<td>
<div class="code">
text: {
unspecifiedRule : 'Please enter a valid value',
unspecifiedField : 'This field'
}
</div>
</td>
</tr>
<tr>
<td>prompt</td>
<td>
<div class="code">
prompt: {
empty : '{name} must have a value',
checked : '{name} must be checked',
email : '{name} must be a valid e-mail',
url : '{name} must be a valid url',
regExp : '{name} is not formatted correctly',
integer : '{name} must be an integer',
decimal : '{name} must be a decimal number',
number : '{name} must be set to a number',
is : '{name} must be \'{ruleValue}\'',
isExactly : '{name} must be exactly \'{ruleValue}\'',
not : '{name} cannot be set to \'{ruleValue}\'',
notExactly : '{name} cannot be set to exactly \'{ruleValue}\'',
contain : '{name} cannot contain \'{ruleValue}\'',
containExactly : '{name} cannot contain exactly \'{ruleValue}\'',
doesntContain : '{name} must contain \'{ruleValue}\'',
doesntContainExactly : '{name} must contain exactly \'{ruleValue}\'',
minLength : '{name} must be at least {ruleValue} characters',
length : '{name} must be at least {ruleValue} characters',
exactLength : '{name} must be exactly {ruleValue} characters',
maxLength : '{name} cannot be longer than {ruleValue} characters',
match : '{name} must match {ruleValue} field',
different : '{name} must have a different value than {ruleValue} field',
creditCard : '{name} must be a valid credit card number',
minCount : '{name} must have at least {ruleValue} choices',
exactCount : '{name} must have exactly {ruleValue} choices',
maxCount : '{name} must have {ruleValue} or less choices'
}
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="no example">
<h4 class="ui header">
Callbacks

3
server/documents/elements/icon.html.eco

@ -1274,6 +1274,9 @@ themes : ['Default']
<div class="example">
<h4 class="ui header">Size</h4>
<p>An icon can vary in size</p>
<i class="mini home icon"></i>
<i class="tiny home icon"></i>
<i class="small home icon"></i>
<i class="small home icon"></i>
<br>
<i class="home icon"></i>

10
server/documents/elements/label.html.eco

@ -79,7 +79,7 @@ themes : ['Default', 'GitHub']
</div>
</div>
<div class="example" data-class="pointing above, pointing below, pointing left, pointing right">
<div class="example" data-class="pointing above, pointing below, left pointing, right pointing">
<h4 class="ui header">Pointing</h4>
<p>A label can point to content next to it</p>
<form class="ui fluid form">
@ -99,13 +99,13 @@ themes : ['Default', 'GitHub']
<div class="ui divider"></div>
<div class="inline field">
<input type="text" placeholder="Username">
<div class="ui pointing left label">
<div class="ui left pointing label">
That name is taken!
</div>
</div>
<div class="ui divider"></div>
<div class="inline field">
<div class="ui pointing right label">
<div class="ui right pointing label">
Your password must be 6 characters or more
</div>
<input type="password">
@ -131,13 +131,13 @@ themes : ['Default', 'GitHub']
<div class="ui divider"></div>
<div class="inline field">
<input type="text" placeholder="Username">
<div class="ui pointing left red basic label">
<div class="ui left pointing red basic label">
That name is taken!
</div>
</div>
<div class="ui divider"></div>
<div class="inline field">
<div class="ui pointing right red basic label">
<div class="ui right pointing red basic label">
Your password must be 6 characters or more
</div>
<input type="password">

63
server/documents/hotfix.html.eco

@ -0,0 +1,63 @@
---
layout : 'blank'
css : 'hotfix'
standalone : true
title : 'Test Page'
type : 'Library'
---
<div class="ui container">
normal:
<div class="ui three column middle aligned grid">
<div class="column">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
</div>
<div class="column">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
</div>
<div class="column">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
</div>
</div>
abnormal:
<div class="ui three column middle aligned grid">
<div class="row">
<div class="column">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
</div>
<div class="column">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
</div>
<div class="column">
<img class="ui image" src="http://semantic-ui.com/images/wireframe/image.png">
</div>
</div>
</div>
</div>
</body>
<!-- TEST JS HERE !-->
<script>
$(document)
.ready(function(){
$('.ui.dropdown')
.dropdown({
allowAdditions: true
})
;
})
;
</script>
<!-- TEST CSS HERE !-->
<style type="text/css">
body > .ui.container:first-child {
margin-top: 5em;
}
</style>

64
server/files/javascript/validate-form.js

@ -6,10 +6,13 @@ semantic.validateForm.ready = function() {
// selector cache
var
$dogForm = $('.dog.example .ui.form'),
$matchingForm = $('.matching.example .ui.form'),
$autoForm = $('.auto.example .ui.form'),
$promptForm = $('.prompt.example .ui.form'),
$dropdownForm = $('.dropdown.example .ui.form'),
$optionalForm = $('.optional.example .ui.form'),
$inlineForm = $('.inline.example .ui.form'),
$form = $('.ui.form').not($dogForm).not($inlineForm).not($dropdownForm).not($optionalForm),
$form = $('.ui.form').not($dogForm).not($inlineForm).not($dropdownForm).not($optionalForm).not($autoForm).not($promptForm),
$checkbox = $('.main.container .ui.checkbox'),
$dropdown = $('.main.container .ui.dropdown'),
// alias
@ -138,6 +141,24 @@ semantic.validateForm.ready = function() {
}
};
$form
.form()
;
$matchingForm
.form({
fields: {
name: {
identifier : 'special-name',
rules: [
{
type : 'empty'
}
]
}
}
})
;
$inlineForm
.form({
@ -173,6 +194,41 @@ semantic.validateForm.ready = function() {
.dropdown()
;
$autoForm
.form({
fields: {
name : 'empty',
gender : 'empty',
username : 'empty',
password : ['minLength[6]', 'empty'],
skills : ['minCount[2]', 'empty'],
terms : 'checked'
}
})
;
$promptForm
.form({
fields: {
field1: {
rules: [
{
type : 'empty'
}
]
},
field2: {
rules: [
{
type : 'exactly[dog]',
prompt : '{name} is set to "{value}" that is totally wrong. It should be {ruleValue}'
}
]
}
}
})
;
$optionalForm
.form({
fields: {
@ -203,7 +259,6 @@ semantic.validateForm.ready = function() {
.form({
fields: {
dog: {
identifier: 'dog',
rules: [
{
type: 'empty',
@ -222,11 +277,6 @@ semantic.validateForm.ready = function() {
}
})
;
$form
.form()
;
};

Loading…
Cancel
Save