Bir önceki yazıya ek yapmak istiyorum.
I want continue my latest article with this article.
Eğer aynı sayfada OnSave() olayı icra edilirken istemediğiniz bir durum oluşursa (örnek olarak bir alana veri girilmemesi); 'event.returnValue' propertysine 'false' değerini vererek, OnSave() olayını icra edilmeden önce durdurup uyarı mesajı gösterebilirsiniz.
Aşağıadaki örnek kod bunu nasıl yapacağımızı bize anlatıyor.
----
On that page you will see that you can stop the onsave event by setting
the 'event.returnValue = false'. Don't forget to follow that line with
a 'return false'. This will cause the save procedure to stop right at
that point. Otherwise statements after that will still be executed.
Below code tell to us how is execute this procedure.
// Example From
SDK//
var
CRM_FORM_SAVE_MODE_SAVE = 1;
var
CRM_FORM_SAVE_MODE_SAVEANDCLOSE = 2;
// Validate only
if the user clicked "Save".
switch (event.Mode)
{
case CRM_FORM_SAVE_MODE_SAVE:
// If the user provided a first and
last name, they must provide
// a job title as well.
if
(crmForm.all.jobtitle.DataValue == ""
&&
crmForm.all.firstname.DataValue != ""
&&
crmForm.all.lastname.DataValue != ""
&&)
{
// Tell the user what is wrong.
alert("Please provide a
Job Title for this person.");
// Give the control focus.
crmForm.all.jobtitle.SetFocus();
// Cancel the save operation.
event.returnValue = false;
return false;
}
break;
case
CRM_FORM_SAVE_MODE_SAVEANDCLOSE:
// If the user forgot to provide a
job title, set a default title.
if
(crmForm.all.jobtitle.DataValue == "")
{
// Set a default Job Title.
crmForm.all.jobtitle.DataValue = "N/A";
// Because this is a "Save
and Close",
// just save the form.
return true;
}
break;
}