cancel
Showing results for 
Search instead for 
Did you mean: 

How to Validate /check the input field value exist in back end DB or not during live change?

Former Member
0 Kudos

Hi Experts,

I have requirement where in need to create the record from SAPui5 application,

For that we have Form and enterthe all details and submit to the data base.

Now i need to validate the first field value, if that value exist in the system/DB need to populate the error, like this record already exist during livechange.

For E.g., Input fields are as follows.

Empld : 121

EmpName : tom

On Change of Empid value need to check 121 record exist in the database or not.

Following are the blogs refereed for the solution but didn't get the solution for the same.

https://blogs.sap.com/2015/10/19/how-to-sapui5-user-input-validations/

https://blogs.sap.com/2015/11/01/generic-sapui5-form-validator/

As i"m new to SAPUI5.Please help me with the coding.

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

ericci
Active Contributor
0 Kudos

The only way to do that is that you bind to the liveChange event of the field, retrive the user input value from the oEvent parameter of the event with oEvent.getParameter("value") and than query your backend system with a $.ajax request.

If the response from the server is ok you can use

oEvent.getSource().setValueState("Success") 

otherwise you set

oEvent.getSource().setValueState("Error")
oEvent.getSource.setValueStateText("This entry already exist on the database.")

Best regards, Emanuele.

Former Member
0 Kudos

This is my code:

onLiveChange: function(event) {

var that = this;

var id = that.byId("id").setValue();

var service_url = "/student/mdc/services/read.xsjs?CMD=select&id=" + id;

$.ajax({

type: "GET", contentType: "application/json",

accept: "application/json",

url: service_url,

success: function(data, textStatus, jqXHR) {

}

i have multiple values to be validated. based on the xsjs service

ericci
Active Contributor
0 Kudos

First of all, you should always use the value and the source from the oEvent.

oEvent.getSource() will give you the element source that triggered the event. In this case the input itself

oEvent.getParameter("value") will give you the text user inputted inside the Input

The instruction that.byId("id").setValue(); that you are using is just resetting the input value to null/empty. It will not work for sure.

What do you mean when you say that you have "multiple values" to be validated? Do you mean that you have different input to validate into the backend?

Former Member
0 Kudos

Yeah i need to validate every field of the page to be validated to not allow duplicate values to the backend.

ericci
Active Contributor
0 Kudos

I cannot validate your code in this way. I already suggested you what you should do in order to get input value, do the AJAX request and how to handle in the UI the result to give a valid feedback to the user.

I cannot do you're homework 😉

Former Member
0 Kudos

OnliveChange:function(oEvent){

var service_url = "/student/mdc/services/select.xsjs?CMD=read";

$.ajax({

type: "GET",

contentType: "application/json",

accept: "application/json",

url: service_url,

success: function(data,response,textStatus, jqXHR) {

},

error: function(jqXHR, textStatus, errorThrown) {

} }); }

Hey Emanuele Ricc can u please help me where to put the code snippet in this.