[Proto-Scripty] Re: Cant get focus to work with change event when tabbing out of input

2009-06-02 Thread T.J. Crowder

> The defer did not work I got  a javascript error  saying this.focus is
> not a function. However, the setTimeout did work

Doh!  My bad.  Should be:

else {
var self = this;
(function(){
self.focus();
}).defer();
alert("invalid number");
return false;

}

-- T.J.

On Jun 2, 2:49 pm, molo  wrote:
> Thank you both for your responses. It's nice to get help. I agree with
> you on the alert being annoying, so I will put a error message out on
> the screen instead of an alert, time permitting (I'm under the gun)
>
> The defer did not work I got  a javascript error  saying this.focus is
> not a function. However, the setTimeout did work
>
> Maurice
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Cant get focus to work with change event when tabbing out of input

2009-06-02 Thread molo

Thank you both for your responses. It's nice to get help. I agree with
you on the alert being annoying, so I will put a error message out on
the screen instead of an alert, time permitting (I'm under the gun)

The defer did not work I got  a javascript error  saying this.focus is
not a function. However, the setTimeout did work

Maurice


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Cant get focus to work with change event when tabbing out of input

2009-06-01 Thread RobG



On Jun 2, 5:32 am, molo  wrote:
> I could use some help. I've been looking at this all day and cannot
> come up with a solution
>
> I am using the same routine on these 5 input fields. If I type in a
> character on one of these fields and press enter, it works as expected
> I get an error alert and focus on the field. However if I type in a
> character and tab out of the field I get an alert error but the focus
> is on the next field. I guess the blur event takes it to the next
> field.
>
> Can someone tell me what I need to do to get the focus working
> correctly here
>
> Here is my event related code
>
>  Event.observe('oldidratio','change',validateNumberChange);
>  Event.observe('cashpershare','change',validateNumberChange);
>  Event.observe('proration','change',validateNumberChange);
>  Event.observe('newid1ratioentry','change',validateNumberChange);
>  Event.observe('newid1fmv','change',validateNumberChange);
>
> Here is the function
>
>    function validateNumberChange(){
>          var numericField = $F(this);

It's an input field and you already have a reference to it, there is
no need to use the $ function:

  var inputValue = this.value;

>        if(IsNumber(numericField,true)){
>           return true;
>        }
>        else {

If the condition is true, it has already returned so there is no need
for an else branch. The statements for the false condition just follow
the if block.


>          $(this).focus();

The focus method belongs to the input, there is no need to use the $
function:

  this.focus();

>          alert("invalid number");

That is a really good way to annoy your users (see TJ's post).  To get
it to "work", use setTimeout to call the focus method:

  var el = this;
  window.setTimeout(function(){el.focus()}, 0);

But I don't recommend doing that.

>          return false;

Why?


--
Rob
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Cant get focus to work with change event when tabbing out of input

2009-06-01 Thread waldron.r...@gmail.com

if i may make a suggestion... you could simplify that by adding a class to each 
of the form elements the using the $$ with invoke...

function validateFn(e){
console.log(e.target.value);
// assuming you use firebug
}
$$('.ClassName').invoke('observe', 'keyup', validateFn); 

hopefully that gets you on the right track


-Original Message-
Date: Monday, June 01, 2009 5:37:48 pm
To: "Prototype & script.aculo.us" 
From: "molo" 
Subject: [Proto-Scripty] Cant get focus to work with change event when tabbing 
out of input


I could use some help. I've been looking at this all day and cannot
come up with a solution

I am using the same routine on these 5 input fields. If I type in a
character on one of these fields and press enter, it works as expected
I get an error alert and focus on the field. However if I type in a
character and tab out of the field I get an alert error but the focus
is on the next field. I guess the blur event takes it to the next
field.

Can someone tell me what I need to do to get the focus working
correctly here

Here is my event related code

 Event.observe('oldidratio','change',validateNumberChange);
 Event.observe('cashpershare','change',validateNumberChange);
 Event.observe('proration','change',validateNumberChange);
 Event.observe('newid1ratioentry','change',validateNumberChange);
 Event.observe('newid1fmv','change',validateNumberChange);

Here is the function

   function validateNumberChange(){
 var numericField = $F(this);
   if(IsNumber(numericField,true)){
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Cant get focus to work with change event when tabbing out of input

2009-06-01 Thread T.J. Crowder

Hi,

My guess (untested, don't know about interplay with alert) is if you
through in a defer[1], it'll work:

else {
(function(){
$(this).focus();
}).defer();
alert("invalid number");
return false;
}

...but that the user experience won't be great for a variety of
reasons (not least because the focus will go to the new field, then
revert to the previous one; and separately, alerts are not great user
experience).

Can I suggest instead, that you validate fields without getting in the
user's way (interfering with their navigation), providing a visual
clue that the field value is not okay (perhaps a red border around the
field, an icon next to it, etc.), and if the user tries to send the
information anyway, at that point using a more intrusive mechanism
(perhaps an alert) to tell them that there are issues and to deal with
the highlighted fields.

[1] http://prototypejs.org/api/function/defer

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Jun 1, 8:32 pm, molo  wrote:
> I could use some help. I've been looking at this all day and cannot
> come up with a solution
>
> I am using the same routine on these 5 input fields. If I type in a
> character on one of these fields and press enter, it works as expected
> I get an error alert and focus on the field. However if I type in a
> character and tab out of the field I get an alert error but the focus
> is on the next field. I guess the blur event takes it to the next
> field.
>
> Can someone tell me what I need to do to get the focus working
> correctly here
>
> Here is my event related code
>
>  Event.observe('oldidratio','change',validateNumberChange);
>  Event.observe('cashpershare','change',validateNumberChange);
>  Event.observe('proration','change',validateNumberChange);
>  Event.observe('newid1ratioentry','change',validateNumberChange);
>  Event.observe('newid1fmv','change',validateNumberChange);
>
> Here is the function
>
>    function validateNumberChange(){
>          var numericField = $F(this);
>        if(IsNumber(numericField,true)){
>           return true;
>        }
>        else {
>          $(this).focus();
>          alert("invalid number");
>          return false;
>        }
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---