Browse Source

adds fixes to inline validation

pull/13/head
Jack Lukic 12 years ago
parent
commit
2d19dd517c
15 changed files with 289 additions and 445 deletions
  1. 94
      build/minified/modules/behavior/form.js
  2. 2
      build/minified/modules/behavior/form.min.js
  3. 2
      build/minified/modules/behavior/state.min.js
  4. 2
      build/minified/modules/dropdown.min.js
  5. 2
      build/minified/modules/form.min.js
  6. 2
      build/minified/modules/popup.min.js
  7. 2
      build/minified/modules/shape.min.js
  8. 94
      build/packaged/modules/behavior/form.js
  9. 6
      build/packaged/semantic.min.js
  10. 94
      build/uncompressed/modules/behavior/form.js
  11. 14
      node/Gruntfile.js
  12. 136
      node/src/documents/modules/form.html
  13. 94
      node/src/files/components/semantic/modules/behavior/form.js
  14. 96
      node/src/files/javascript/validate-form.js
  15. 94
      src/modules/behavior/form.js

94
build/minified/modules/behavior/form.js

@ -56,7 +56,7 @@ $.fn.form = function(fields, parameters) {
module = {
initialize: function() {
module.verbose('Initializing form validation');
module.verbose('Initializing form validation', $module, validation, settings);
if(settings.keyboardShortcuts) {
$field
.on('keydown' + eventNamespace, module.event.field.keydown)
@ -66,7 +66,7 @@ $.fn.form = function(fields, parameters) {
.on('submit' + eventNamespace, module.validate.form)
;
$field
.on('change' + eventNamespace, module.event.field.change)
.on('blur' + eventNamespace, module.event.field.change)
;
$submit
.on('click' + eventNamespace, module.submit)
@ -129,6 +129,7 @@ $.fn.form = function(fields, parameters) {
$field = $(this),
$fieldGroup = $field.closest($group)
;
console.log('here', settings.on);
if( $fieldGroup.hasClass(className.error) ) {
module.debug('Revalidating field', $field, module.get.validation($field));
module.validate.field( module.get.validation($field) );
@ -176,10 +177,10 @@ $.fn.form = function(fields, parameters) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
return true
return true;
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
return true
return true;
}
return false;
}
@ -248,7 +249,7 @@ $.fn.form = function(fields, parameters) {
;
// reset errors
formErrors = [];
$.each(validation, function(fieldName, field){
$.each(validation, function(fieldName, field) {
if( !( module.validate.field(field) ) ) {
allValid = false;
}
@ -485,11 +486,11 @@ $.fn.form.settings = {
moduleName : 'Form',
debug : true,
verbose : true,
performance : true,
performance : false,
namespace : 'validate',
keyboardShortcuts : true,
on : 'change',
on : 'submit',
animateSpeed : 150,
inlineError : false,
@ -524,84 +525,7 @@ $.fn.form.settings = {
method : 'The method you called is not defined.'
},
defaults: {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
},
templates: {
error: function(errors) {

2
build/minified/modules/behavior/form.min.js
File diff suppressed because it is too large
View File

2
build/minified/modules/behavior/state.min.js
File diff suppressed because it is too large
View File

2
build/minified/modules/dropdown.min.js
File diff suppressed because it is too large
View File

2
build/minified/modules/form.min.js
File diff suppressed because it is too large
View File

2
build/minified/modules/popup.min.js
File diff suppressed because it is too large
View File

2
build/minified/modules/shape.min.js
File diff suppressed because it is too large
View File

94
build/packaged/modules/behavior/form.js

@ -56,7 +56,7 @@ $.fn.form = function(fields, parameters) {
module = {
initialize: function() {
module.verbose('Initializing form validation');
module.verbose('Initializing form validation', $module, validation, settings);
if(settings.keyboardShortcuts) {
$field
.on('keydown' + eventNamespace, module.event.field.keydown)
@ -66,7 +66,7 @@ $.fn.form = function(fields, parameters) {
.on('submit' + eventNamespace, module.validate.form)
;
$field
.on('change' + eventNamespace, module.event.field.change)
.on('blur' + eventNamespace, module.event.field.change)
;
$submit
.on('click' + eventNamespace, module.submit)
@ -129,6 +129,7 @@ $.fn.form = function(fields, parameters) {
$field = $(this),
$fieldGroup = $field.closest($group)
;
console.log('here', settings.on);
if( $fieldGroup.hasClass(className.error) ) {
module.debug('Revalidating field', $field, module.get.validation($field));
module.validate.field( module.get.validation($field) );
@ -176,10 +177,10 @@ $.fn.form = function(fields, parameters) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
return true
return true;
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
return true
return true;
}
return false;
}
@ -248,7 +249,7 @@ $.fn.form = function(fields, parameters) {
;
// reset errors
formErrors = [];
$.each(validation, function(fieldName, field){
$.each(validation, function(fieldName, field) {
if( !( module.validate.field(field) ) ) {
allValid = false;
}
@ -485,11 +486,11 @@ $.fn.form.settings = {
moduleName : 'Form',
debug : true,
verbose : true,
performance : true,
performance : false,
namespace : 'validate',
keyboardShortcuts : true,
on : 'change',
on : 'submit',
animateSpeed : 150,
inlineError : false,
@ -524,84 +525,7 @@ $.fn.form.settings = {
method : 'The method you called is not defined.'
},
defaults: {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
},
templates: {
error: function(errors) {

6
build/packaged/semantic.min.js
File diff suppressed because it is too large
View File

94
build/uncompressed/modules/behavior/form.js

@ -56,7 +56,7 @@ $.fn.form = function(fields, parameters) {
module = {
initialize: function() {
module.verbose('Initializing form validation');
module.verbose('Initializing form validation', $module, validation, settings);
if(settings.keyboardShortcuts) {
$field
.on('keydown' + eventNamespace, module.event.field.keydown)
@ -66,7 +66,7 @@ $.fn.form = function(fields, parameters) {
.on('submit' + eventNamespace, module.validate.form)
;
$field
.on('change' + eventNamespace, module.event.field.change)
.on('blur' + eventNamespace, module.event.field.change)
;
$submit
.on('click' + eventNamespace, module.submit)
@ -129,6 +129,7 @@ $.fn.form = function(fields, parameters) {
$field = $(this),
$fieldGroup = $field.closest($group)
;
console.log('here', settings.on);
if( $fieldGroup.hasClass(className.error) ) {
module.debug('Revalidating field', $field, module.get.validation($field));
module.validate.field( module.get.validation($field) );
@ -176,10 +177,10 @@ $.fn.form = function(fields, parameters) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
return true
return true;
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
return true
return true;
}
return false;
}
@ -248,7 +249,7 @@ $.fn.form = function(fields, parameters) {
;
// reset errors
formErrors = [];
$.each(validation, function(fieldName, field){
$.each(validation, function(fieldName, field) {
if( !( module.validate.field(field) ) ) {
allValid = false;
}
@ -485,11 +486,11 @@ $.fn.form.settings = {
moduleName : 'Form',
debug : true,
verbose : true,
performance : true,
performance : false,
namespace : 'validate',
keyboardShortcuts : true,
on : 'change',
on : 'submit',
animateSpeed : 150,
inlineError : false,
@ -524,84 +525,7 @@ $.fn.form.settings = {
method : 'The method you called is not defined.'
},
defaults: {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
},
templates: {
error: function(errors) {

14
node/Gruntfile.js

@ -57,6 +57,19 @@ module.exports = function(grunt) {
}
},
docco: {
generate: {
expand : true,
cwd : '../spec',
src : [
'**/*.commented.js'
],
options: {
output: 'src/files/generated/'
}
}
},
less: {
options: {
compress : false,
@ -202,6 +215,7 @@ module.exports = function(grunt) {
};
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-docco');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-css');

136
node/src/documents/modules/form.html

@ -29,7 +29,12 @@ type : 'UI Module'
<div class="example">
<h4>Basic Validation</h4>
<p>Form validation requires passing in a validation object with the rules required to validate your form.</p>
<div class="ui green message">If no validation object is specified then the form will validate against the default validation set up for the plugin. </div>
<div class="ui green message">If no validation object is specified then the form will validate against the default validation set up for the plugin. See <em>default validation</em> below.</div>
<div class="ignore code">
$('.ui.form')
.form()
;
</div>
<div class="ui form segment">
<p>Let's go ahead and get you signed up.</p>
<div class="two fields">
@ -65,11 +70,7 @@ type : 'UI Module'
<h4>Validation w/ Message</h4>
<p>Forms that contain a <a href="elements/message.html">ui message</a> error block will automatically be filled in with form validation information.</p>
<div class="info message">The template for error messages can be modified by adjusting settings.template.error</div>
<div class="ignore code">
$('.ui.form')
.form()
;
</div>
<div class="ui form segment">
<p>Let's go ahead and get you signed up.</p>
<div class="two fields">
@ -101,7 +102,6 @@ type : 'UI Module'
<div class="ui error message"></div>
</div>
</div>
<div class="dog example">
<h4>Custom Validation</h4>
<p>Custom form validation requires passing in a validation object with the rules required to validate your form.</p>
@ -142,6 +142,128 @@ type : 'UI Module'
</div>
</div>
<div class="inline example">
<h4>Inline Validation</h4>
<p>Validation messages can also appear inline. UI Forms automatically format <a href="/elements/label.html">labels</a> with the className prompt. These validation prompts are also set to appear on input change instead of form submission.</p>
<div class="ui form segment">
<p>Let's go ahead and get you signed up.</p>
<div class="two fields">
<div class="field">
<label>First Name</label>
<input placeholder="First Name" name="first-name" type="text">
</div>
<div class="field">
<label>Last Name</label>
<input placeholder="Last Name" name="last-name" type="text">
</div>
</div>
<div class="field">
<label>Username</label>
<input placeholder="Username" name="username" type="text">
</div>
<div class="field">
<label>Password</label>
<input type="password" name="password">
</div>
<div class="inline field">
<div class="ui checkbox">
<input type="checkbox" name="terms" />
<label class="box"></label>
</div>
<label>I agree to the terms and conditions</label>
</div>
<div class="ui blue submit button">Submit</div>
</div>
</div>
<div class="example">
<h4>Setting Defaults</h4>
<p>It may be useful to set default form validation values, since similar fields are often validated across multiple forms. This can be done by modifying the defaults of the settings object</p>
<div class="code">
$.fn.form.settings.defaults = {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
};
</div>
</div>
<h2>Settings</h2>

94
node/src/files/components/semantic/modules/behavior/form.js

@ -56,7 +56,7 @@ $.fn.form = function(fields, parameters) {
module = {
initialize: function() {
module.verbose('Initializing form validation');
module.verbose('Initializing form validation', $module, validation, settings);
if(settings.keyboardShortcuts) {
$field
.on('keydown' + eventNamespace, module.event.field.keydown)
@ -66,7 +66,7 @@ $.fn.form = function(fields, parameters) {
.on('submit' + eventNamespace, module.validate.form)
;
$field
.on('change' + eventNamespace, module.event.field.change)
.on('blur' + eventNamespace, module.event.field.change)
;
$submit
.on('click' + eventNamespace, module.submit)
@ -129,6 +129,7 @@ $.fn.form = function(fields, parameters) {
$field = $(this),
$fieldGroup = $field.closest($group)
;
console.log('here', settings.on);
if( $fieldGroup.hasClass(className.error) ) {
module.debug('Revalidating field', $field, module.get.validation($field));
module.validate.field( module.get.validation($field) );
@ -176,10 +177,10 @@ $.fn.form = function(fields, parameters) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
return true
return true;
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
return true
return true;
}
return false;
}
@ -248,7 +249,7 @@ $.fn.form = function(fields, parameters) {
;
// reset errors
formErrors = [];
$.each(validation, function(fieldName, field){
$.each(validation, function(fieldName, field) {
if( !( module.validate.field(field) ) ) {
allValid = false;
}
@ -485,11 +486,11 @@ $.fn.form.settings = {
moduleName : 'Form',
debug : true,
verbose : true,
performance : true,
performance : false,
namespace : 'validate',
keyboardShortcuts : true,
on : 'change',
on : 'submit',
animateSpeed : 150,
inlineError : false,
@ -524,84 +525,7 @@ $.fn.form.settings = {
method : 'The method you called is not defined.'
},
defaults: {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
},
templates: {
error: function(errors) {

96
node/src/files/javascript/validate-form.js

@ -5,9 +5,10 @@ semantic.validateForm.ready = function() {
// selector cache
var
$dogForm = $('.dog.example .ui.form'),
$form = $('.ui.form').not($dogForm),
$checkbox = $('.ui.checkbox'),
$dogForm = $('.dog.example .ui.form'),
$inlineForm = $('.inline.example .ui.form'),
$form = $('.ui.form').not($dogForm).not($inlineForm),
$checkbox = $('.ui.checkbox'),
// alias
handler
;
@ -16,11 +17,98 @@ semantic.validateForm.ready = function() {
handler = {
};
$checkbox
.checkbox()
;
$.fn.form.settings.defaults = {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
};
$inlineForm
.form({}, {
on: 'change',
inlineError: true
})
;
$dogForm
.form({
dog: {

94
src/modules/behavior/form.js

@ -56,7 +56,7 @@ $.fn.form = function(fields, parameters) {
module = {
initialize: function() {
module.verbose('Initializing form validation');
module.verbose('Initializing form validation', $module, validation, settings);
if(settings.keyboardShortcuts) {
$field
.on('keydown' + eventNamespace, module.event.field.keydown)
@ -66,7 +66,7 @@ $.fn.form = function(fields, parameters) {
.on('submit' + eventNamespace, module.validate.form)
;
$field
.on('change' + eventNamespace, module.event.field.change)
.on('blur' + eventNamespace, module.event.field.change)
;
$submit
.on('click' + eventNamespace, module.submit)
@ -129,6 +129,7 @@ $.fn.form = function(fields, parameters) {
$field = $(this),
$fieldGroup = $field.closest($group)
;
console.log('here', settings.on);
if( $fieldGroup.hasClass(className.error) ) {
module.debug('Revalidating field', $field, module.get.validation($field));
module.validate.field( module.get.validation($field) );
@ -176,10 +177,10 @@ $.fn.form = function(fields, parameters) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').size() > 0 ) {
return true
return true;
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').size() > 0 ) {
return true
return true;
}
return false;
}
@ -248,7 +249,7 @@ $.fn.form = function(fields, parameters) {
;
// reset errors
formErrors = [];
$.each(validation, function(fieldName, field){
$.each(validation, function(fieldName, field) {
if( !( module.validate.field(field) ) ) {
allValid = false;
}
@ -485,11 +486,11 @@ $.fn.form.settings = {
moduleName : 'Form',
debug : true,
verbose : true,
performance : true,
performance : false,
namespace : 'validate',
keyboardShortcuts : true,
on : 'change',
on : 'submit',
animateSpeed : 150,
inlineError : false,
@ -524,84 +525,7 @@ $.fn.form.settings = {
method : 'The method you called is not defined.'
},
defaults: {
firstName: {
identifier : 'first-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your first name'
}
]
},
lastName: {
identifier : 'last-name',
rules: [
{
type : 'empty',
prompt : 'Please enter your last name'
}
]
},
username: {
identifier : 'username',
rules: [
{
type : 'empty',
prompt : 'Please enter a username'
}
]
},
email: {
identifier : 'email',
rules: [
{
type : 'empty',
prompt : 'Please enter your email'
},
{
type : 'email',
prompt : 'Please enter a valid email'
}
]
},
password: {
identifier : 'password',
rules: [
{
type : 'empty',
prompt : 'Please enter a password'
},
{
type : 'length[6]',
prompt : 'Your password must be at least 6 characters'
}
]
},
passwordConfirm: {
identifier : 'password-confirm',
rules: [
{
type : 'empty',
prompt : 'Please confirm your password'
},
{
identifier : 'password-confirm',
type : 'match[password]',
prompt : 'Please verify password matches'
}
]
},
terms: {
identifier : 'terms',
rules: [
{
type : 'checked',
prompt : 'You must agree to the terms and conditions'
}
]
}
},
templates: {
error: function(errors) {

Loading…
Cancel
Save