[jQuery] numeric plugin and the minus sign
Ok the problem with this plugin is that you can only specify a minus
sign when the string length is zero, but since the code only allows
numbers, decimal places and the minus sign to be entered we can assume
that the if the length of the string is greater than zero that it is a
valid number so if we multiply it by -1 we will negate it thus if you
cursor in at any position in the number the minus key will make the
number a minus number.
Now if you remove the "if (this.value*1 >0){" condition then you can
toggle the number to be a positive/negative value using the minus sign
Ok so from a usability point of view this would probably never be used
ie if someone wanted to make the number a negative number they would
probably move te cursor to the start of the number and hit the minus
key. but since we don't really care if the cursor is at the start or not
we can do the work for them
--- the code ---
find the following 2 lines in the numeric plugin
------------------------- code ----------------------------
/* '-' only allowed at start */
if(key == 45 && this.value.length == 0) return true;
------------------------- /code ---------------------------
and add the follwoing block of code
------------------------- code ----------------------------
/* '-' make number negative */
if(key == 45){
if(this.value.length != 0) {
// remove this next line to toggle between negative and
positive numbers
if (this.value*1 >0){
this.value = this.value * -1;
return false;
}
}
}
------------------------- /code ---------------------------
___________________________________________________________
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/