Xamarin Forms sfDataForm with drop Down select item ( Issue in post with select item ) please help

I have two models and one ViewModel and XAML  my issue in a post in API (I  get selected item from API is working but the post not working please help me with this issue please )

Model --------------------------------------------------

 public class HrTime

    {

        [JsonProperty("timeID")]

        public string TimeId { get; set; }

    }


    public class HrPostTimeRequest

    {

        public string pernr { get; set; }

        public HrTime  t_REQ_ID { get; set; }   //  type form list HrTime model

        public string datE_FR { get; set; }

        public string datE_TO { get; set; }

        public string timE_FR { get; set; }

        public string timE_TO { get; set; }

        public string approved { get; set; }

        public string createD_AT { get; set; }

        public string approveD_AT { get; set; }

        public string note { get; set; }

    }

-------------------------------------------------------------------------


and


view model is -----------------------------------------------------------------------------------


using Newtonsoft.Json;

using MyAPP.Modles;

using System.ComponentModel;

using System.Net.Http;

using System.Text;

using Xamarin.Forms;

using System.Runtime.CompilerServices;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System;

using System.Windows.Input;

using System.Threading.Tasks;


namespace MyAPP.ViewModels

{


    public class HrTimeTestViewModel : INotifyPropertyChanged

    {

        private ObservableCollection<HrTime> eHrTime;

        public ObservableCollection<HrTime> EHrTime

        {

            get { return eHrTime; }

            set {

                eHrTime = value;

                this.OnPropertyChanged("EHrTime");

                }

        }


        private HrTime oeHrTime;

        public HrTime OEHrTime

        {

            get { return oeHrTime; }

            set {

                oeHrTime = value;

                this.OnPropertyChanged("OEHrTime");

            }

        }



        private HrPostTimeRequest eTimePost;

        public HrPostTimeRequest ETimePost

        {

            get { return eTimePost; }

            set { eTimePost = value;

                this.OnPropertyChanged("ETimePost");

            }

        }


        public ICommand HrTimeTypeOn { get; set; }

        public ICommand PostHrTimeTypeOn { get; set; }


        public HrTimeTestViewModel()

        {

            EHrTime = new ObservableCollection<HrTime>();

            HrTimeTypeOn = new Command(OnLoadtype);

            PostHrTimeTypeOn = new Command(OnPostHrTimeTypeOn);

           this.getHrTimme();

        }


        void getHrTimme()

        {

            Task.Run(async () =>

            {

                try

                {

                    OnLoadtype();

                }

                catch (Exception e)

                {

                    await App.Current.MainPage.DisplayAlert("Alert",e.Message, "Ok");

                }

            });

        }


        async void OnLoadtype()

        {


            var httpClient = new HttpClient();

            var httpRequest = new HttpRequestMessage();

            string urlList = "https://BaseLink.com/api/us/GetTimeReqestType";

            httpRequest.RequestUri = new Uri(urlList);

            httpRequest.Method = HttpMethod.Get;

            var response = await httpClient.SendAsync(httpRequest);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)

            {

                var content = response.Content;

                var json = await content.ReadAsStringAsync();

                var extractingData = JsonConvert.DeserializeObject<ObservableCollection<HrTime>>(json);

                EHrTime = extractingData;

            }

        }

        async void OnPostHrTimeTypeOn()

        {

            string url = "https://api.BaseLink.com/api/us/PosReqest";

            HttpClient client = new HttpClient();

            ETimePost.t_REQ_ID = oeHrTime;

         // Console.WriteLine("ttt")

            string jsonData = JsonConvert.SerializeObject(ETimePost);

            StringContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");

            HttpResponseMessage responsew = await client.PostAsync(url, content);

            string result = await responsew.Content.ReadAsStringAsync();

            Response responseData = JsonConvert.DeserializeObject<Response>(result);

            if (responseData.Status == 200)

            {

                await App.Current.MainPage.DisplayAlert("Alert", Data Saved ", "Ok");

            }

            else

            {

                await App.Current.MainPage.DisplayAlert("Alert", "please check the data ", "Ok");

            }

        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)

        {

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

        }

    }

}


and my Design in XAML is -------------------------------------


<StackLayout x:Name="stacklayout" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">

                <ScrollView>

                    <dataForm:SfDataForm x:Name="dataForm" DataObject="{Binding PostHrTimeTypeOn}"

                                     AutoGenerateItems="False" VerticalOptions="FillAndExpand"

                                     HorizontalOptions="FillAndExpand" LabelPosition="Top">

                        <dataForm:SfDataForm.Items>

                            <dataForm:DataFormTextItem Name="Pernr" Editor="Text"/>

                            <dataForm:DataFormDropDownItem x:Name="dropdownn"

                             Editor="DropDown" DisplayMemberPath="TimeId" SelectedValuePath="TimeId"

                            BindingContext="{StaticResource client}"

                            ItemsSource = "{Binding EHrTime}"/>

                            <dataForm:DataFormDateItem Name="DatE_FR" Editor="Date"/>

                            <dataForm:DataFormDateItem Name="DatE_TO" Editor="Date"/>

                            <dataForm:DataFormTimeItem Name="TimE_FR" Editor="Time" Format="HH:mm"/>

                            <dataForm:DataFormTimeItem Name="TimE_TO" Editor="Time" Format="HH:mm"/>

                            <dataForm:DataFormNumericItem Name="Approved" Editor="Text"/>

                            <dataForm:DataFormTextItem Name="CreateD_AT" Editor="Text"/>

                            <dataForm:DataFormTextItem Name="ApproveD_AT" Editor="Text"/>

                            <dataForm:DataFormTextItem Name="Note" Editor="MultilineText"/>

                        </dataForm:SfDataForm.Items>

                    </dataForm:SfDataForm>

                </ScrollView>

                <Button Text="Save" BindingContext="{StaticResource client}" Command="{Binding PostHrTimeTypeOn }"/>

            </StackLayout>




3 Replies

SS SaiGanesh Sakthivel Syncfusion Team December 23, 2021 05:26 AM UTC

Hi Saber, 
 
#Regarding SfDataFormDropdown editor with select item 
We could not replicate the reported scenario in our simple sample from our end. We have prepared the simple sample as per given information and attached the tested sample in the following locations. 
 
 
Please check the sample and let us know if you still facing the same issue? If not, please modify our sample based on your scenario and revert us back with the following details,  
 
·       Share the syncfusion version used in the sample. 
  
It will be helpful for us to check on it and provide you the solution at the earliest.  
   
Regards,
SaiGanesh Sakthivel 
 



SM Saber Mohamed Hassan December 23, 2021 04:59 PM UTC

    can't find the    SelectedValue="{Binding timeID, Mode=TwoWay}"    like in

combobox:SfComboBox



Please help urgent 



SS SaiGanesh Sakthivel Syncfusion Team December 27, 2021 06:26 AM UTC

Hi Saber, 
 
We suggest you use the SelectedValuePath property to get the value of the selected data in the DataObject in SfDataForm. Please refer to the code snippet for your reference. 
 
Code snippet 
<dataForm:SfDataForm x:Name="dataForm" DataObject="{Binding ContactsInfo}" Grid.Row="1" LayoutOptions="TextInputLayout"   AutoGenerateItems="False"> 
    <dataForm:SfDataForm.Items> 
        <dataForm:DataFormDateItem Name="FirstName" Editor="Text" /> 
        <dataForm:DataFormDateItem Name="LastName" Editor="Text"/> 
        <dataForm:DataFormDropDownItem Name="Country" BindingContext="{x:Reference Client}" Editor="DropDown" ItemsSource ="{Binding Addresses}" DisplayMemberPath="City" SelectedValuePath="City" /> 
    </dataForm:SfDataForm.Items> 
</dataForm:SfDataForm> 
 
Please refer to the sample in the following location. 
 
Please let us know if you have any concerns. 
 
Regards,
SaiGanesh Sakthivel
 


Loader.
Up arrow icon