Any one run into this and ideas?
var oField = event.srcElement;
var phonedigits;
phonedigits = oField.DataValue.length;
if (phonedigits < 10)
{
alert("Phone number must have at least 10 digits")
oField.SetFocus();
return = false;
}
--
Nick Doelman
www.readybms.com
//Use the below code to setFocus the Field
// Set focus to the field
crmForm.all.SOME_FIELD_ID.SetFocus();
--
Please mark this post as helpful, if it resolves your query.
Thanks & Regards,
Ranjitsingh Raghuvanshi
MS Small Business CRM Certified Professional.
http://mscrm-developer.blogspot.com/
My code was designed for portability, that is why I used the variable for
the field, however that is not the issue.
Replacing my code with this:
if (crmForm.all.telephone1.DataValue.length < 10)
{
alert("Phone number must have at least 10 digits")
crmForm.all.telephone1.SetFocus();
return false;
}
Does the following in CRM 3.0:
-alerts the user that the phone number they are entering needs to be at
least 10 digits
-sets the focus *back* to the telephone1 field
-stops cursor from moving to the next field, cursor remains in telephone1
field
Does the following in CRM 4.0:
-alerts the user that the phone number they are entering needs to be at
least 10 digits
-sets the focus *back* to the telephone1 field
-the cursor move to the next field anyway, cursor is now in the next field
on the form in the tab order
The setFocus() is working, but in CRM 4.0 the action of tabbing to next
field is not cancelled.
It appears that CRM 4.0 is interpreting jscript code slightly differently in
certain cases (e.g. "eventReturn = false" no longer works in onchange events)
Ultimately what I want is if the user does not enter correct data, leave the
focus in the field until they do.
Thanks!
Nick
--
Nick Doelman
www.readybms.com
i've found exactly the same problem that you're experiencing, have you found
any answers?
thanks
ian
Unfortunately not, I ended up putting the verfication logic in the "onsave"
event that did put the focus back to that field, but I would have rather let
the user fix right then and there and had the focus reset immediately.
I wish I had the answer!
Nick
--
Nick Doelman
www.readybms.com
ian
I'm also working on validation of a phone number field and don't want the user to be able to proceed unless the field is blank, or it follows my validation rules.
This is my full solution for validating a 10 or 7 character phone number. Original source was obtained from elsewhere on the net...just added the extra SetFocus line as shown...
// Grab the value from the field that generated the onChange event
var oField = event.srcElement;
// We're cool if the field is empty, otherwise validate it
if (oField.DataValue != "undefined" && oField.DataValue != null)
{
// Strip non-numerics
var sTmp = oField.DataValue.replace(/[^0-9]/g, "");
// Count the digits in the string...we need 10 to mask the phone number properly
switch (sTmp.length)
{
case 10:
oField.DataValue = "(" + sTmp.substr(0, 3) + ") " + sTmp.substr(3, 3) + "-"
+ sTmp.substr(6, 4);
break;
// Could easily validate 7 digit numbers as well
// case 7:
// oField.DataValue = sTmp.substr(0, 3) + "-" + sTmp.substr(3, 4);
// break;
// No match on 10 or 7 digit numbers...throw an error.
default:
alert("Phone number must contain exactly 10 digits");
// the next two lines are a workaround for CRM which doesn't set the Focus properly.
// First set focus to some other field on the form...we chose firstname here
// Then, set focus to the form field that began this onChange event
// declared oField
crmForm.all.firstname.SetFocus();
oField.SetFocus();
break;
}
}
Very weird, but the result is what I wanted. The focus REMAINS on the fidle that started the onChange, with all the text preselected.
Hope it works for you..
JB
IanOldbur wrote:
RE: SetFocus not sticking in CRM 4.0
13-Mar-08
cheers for your update, if/ when the answer appears i'll let you know.
ian
"Nick Doelman" wrote:
EggHeadCafe - Software Developer Portal of Choice
WPF And The Model View View Model Pattern
http://www.eggheadcafe.com/tutorials/aspnet/ec832ac7-6e4c-4ea8-81ab-7374d3da3425/wpf-and-the-model-view-vi.aspx
Larry Trimble wrote:
SetFocus not sticking in CRM 4.0 - Workaround
24-Sep-09
JB
EggHeadCafe - Software Developer Portal of Choice
Here's a simple workaround that works fine for me :
var oField = crmForm.all.crm_myfield;
oField.onblur = function() {
oField.SetFocus();
oField.onblur = null;
}
oField.SetFocus();
The onblur event is triggered when an element loses the focus.
So, crmForm loads, I call SetFocus, the field receives the focus and after
one milisec loses it. So the bug has been executed. Then, onblur is called,
and the field gets the focus again. To allow the user to click on other
field, remove the onblur event.
It works at my customer!
--
Nicolas Pagès