Forums: Field Events use case - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Field Events use case

#1 User is offline   jadach 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 315
  • Joined: 26-April 08

Posted 09 September 2017 - 07:15 PM

Using field events to let users know before saving a record that a record already exists.

My scenario is I do not want a duplicate Job Title added to the table.

In order to prevent a duplicate field value added, we typically use the "Check if specific record exists" before record added event. Something like:

string strSQLExists = "select JobTitle from dbo.Jobs where JobTitle='"+values["JobTitle"].ToString()+"'";
XVar rsExists = CommonFunctions.db_query(strSQLExists, null);
XVar data = CommonFunctions.db_fetch_array(rsExists);
if(data)
{
message = "This Job Title already exisits.";
return false;
}
else
{
return true;
}


This works perfectly, but wouldn't it be nice if we could let the user know before they even click save?

Here is how we can do that:

On the fields section, click properties of the field you do not want a duplicate. In the upper right, click Field Events.

Your event should be set to editing (dropdown on top). Now click New Handler.

Client Before:
params["val"] = this.getValue();


Server:
string strSQLExists = "select * from Careers.dbo.Jobs where JobTitle='"+parameters["val"].ToString()+"'";
XVar rsExists = CommonFunctions.db_query(strSQLExists, null);
XVar data = CommonFunctions.db_fetch_array(rsExists);
if(data)
{
result["newJobTitle"] = parameters["val"].ToString() + " " + "exists. Please enter another title.";
}
else
{
result["newJobTitle"] = "";
}


Client After:
$("#JobTitleTip").remove();
$("input[id=value_JobTitle_1]").after("<div id='JobTitleTip' style='margin-top: 10px; color: red; font-size: 120%;'>"+result["newJobTitle"]+"</div>");


There you go.

Posted Image

Now having said all that. This scenario can also be accomplished with a simple click of a box. I just wanted to demonstrate the Field Events in action.

Posted Image
-jerry
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic