We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Commit via Button

How do i access the values from the individual fields when a button action is performed and validation is done? I want to pass those values to a rest service. what will be the best approach?

        private void OnCommit(object dataForm)
        {
            var dataFormLayout = dataForm as Syncfusion.XForms.DataForm.SfDataForm;
            var isValid = dataFormLayout.Validate();
            dataFormLayout.Commit();
            if (!isValid)
            {
                App.Current.MainPage.DisplayAlert("Alert", "Please enter valid details", "Ok");
                return;
            }

            App.Current.MainPage.DisplayAlert("Alert", "Money Transferred", "Ok");  // Here I want to perform the API Call. 
            dataFormLayout.IsReadOnly = true;
            this.IsVisible = false;
        }

3 Replies

KA Karthikraja Arumugam Syncfusion Team January 9, 2020 06:49 AM UTC

Hi Emad, 
 
Thank you for contacting Syncfusion support. 
 
Based on the shared information we have checked your requirement of “Accessing field values after DataForm commit”. DataForm DataObject will hold the committed values of each field, you can get the entire class or individual field values from DataObject of DataForm. 
 
Please refer the following code example for the same, 
 
[C#] 
private void OnCommit(object dataForm) 
            var dataFormLayout = dataForm as Syncfusion.XForms.DataForm.SfDataForm; 
            var isValid = dataFormLayout.Validate(); 
            dataFormLayout.Commit(); 
 
            //Gets value of model class 
            var model = dataFormLayout.DataObject; 
 
            //Gets individual field values 
            var firstName = (dataFormLayout.DataObject as ContactsInfo).FirstName; 
            var lastName = (dataFormLayout.DataObject as ContactsInfo).LastName; 
            var email = (dataFormLayout.DataObject as ContactsInfo).Email; 
            var contactNumber = (dataFormLayout.DataObject as ContactsInfo).ContactNumber; 
 
 
We have prepared a sample based on your requirement, 
Link: DataForm 
 
We hope this helps. Please let us know if you would require any further assistance. 
 
Regards, 
Karthik Raja A 



EA Emad Afaq January 9, 2020 07:12 AM UTC

Great!, I will give it a shot. Thanks Alot


KA Karthikraja Arumugam Syncfusion Team January 9, 2020 07:16 AM UTC

Hi Emad, 
 
We are glad that the provided information helped you to achieve your requirements. Please get in touch with us if you would require further assistance. We are always happy to assist you. 
 
Regards, 
Karthik Raja A 


Loader.
Live Chat Icon For mobile
Up arrow icon