Skip to content

Commit

Permalink
total removal of control.value()
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Dorofeev <aka.spin@gmail.com>
  • Loading branch information
akaspin committed Feb 8, 2012
1 parent 6961f09 commit 2bdf5e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
6 changes: 3 additions & 3 deletions jquery.f51.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
$$.bind('input change', function() {
var $$ = $(this);
var field = $$.get(0);
var value = field.control.value();
var value = field.value;
var async = field.control.async;

var clearAsync = function() {
setAsyncState($$, '', opts);
clearTimeout(async.pending);
async.value = field.control.value();
async.value = field.value;
form.trigger('state');
}

Expand Down Expand Up @@ -102,7 +102,7 @@
async.pending = setTimeout(function() {
op.apply(field, [function(newMsg) {
newMsg = newMsg || '';
if (field.control.value() == async.value
if (field.value == async.value
&& isAsyncClear(field)
&& isSysValid(field)) {
setAsyncState($$, newMsg, opts);
Expand Down
23 changes: 2 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,6 @@ field and it will be in an invalid state until the custom message is set
back to an empty string. Details
[here](http://dev.w3.org/html5/spec/Overview.html#dom-cva-setcustomvalidity).


## Field value and placeholder

At this time, all implementations of placeholders in old browsers based on the
replacement of an empty field value to a value of placeholder. And if you try
to get the value of an empty field via element `value` property or jQuery
`.val()` function, you get the value of placeholder.

To deal with this `f5` provide element `.control.value()` function:

> $('your-field').val()
< "Some placeholder"
> $('your-field').get(0).control.value()
< ""

`f5` also cleans field values before form submit.


## Validation chain

All restrictions of field in HTML5 are arrayed in a chain: `required`, field
Expand All @@ -91,8 +73,7 @@ forms. In following example `f5` is initialized with default options:
classes : {
valid : 'valid',
invalid : 'invalid',
required : 'required',
placeholder : 'placeholder'
required : 'required'
},
messages : {
required : "Please fill out this field.",
Expand Down Expand Up @@ -232,7 +213,7 @@ add validator function to `f51` options:
var that = this;
// Long-long...
setTimeout(function(){
(this.control.value() == 'somevalue') ?
(this.value == 'somevalue') ?
callback() : callback('Value must be "somevalue".');
} ,3000);
}
Expand Down
8 changes: 4 additions & 4 deletions test/test-f51.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<script type="text/javascript" src="../jquery.f5.js"></script>
<script type="text/javascript" src="../jquery.f51.js"></script>

<title>jquery.f5 Test</title>
<title>jquery.f51 Test</title>
</head>

<body>
<h1>jquery.f5 Test</h1>
<h1>jquery.f51 Test</h1>

<form id='f' >
<fieldset><legend>Text</legend>
Expand Down Expand Up @@ -98,14 +98,14 @@ <h1>jquery.f5 Test</h1>
async3: function(callback) {
var that = this;
setTimeout(function() {
that.control.value() == 'async' ?
that.value == 'async' ?
callback() : callback('Not "async".')
}, 3000);
},
async1: function(callback) {
var that = this;
setTimeout(function() {
that.control.value() == 'async' ?
that.value == 'async' ?
callback() : callback('Not "async".')
}, 1000);
}
Expand Down

0 comments on commit 2bdf5e6

Please sign in to comment.