[CLOSED] ComboBox Change Event get fire on binding with model value

  1. #1

    [CLOSED] ComboBox Change Event get fire on binding with model value

    Hi,

    I am having model with certain value, which I bind to form panel controls. I want to fire a ComboBox change event to call a funtion, so I have added listener to ComboBox. But unfortunately that function get call as ComboBox get bound with model field.

    Can you please tell me, how to avoid that call? Following is code sample.
    Let me know if I am doing something wrong.

    //Model
    public class Person
        {
            public string ID { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public DateTime DateOfBirth { get; set; }
            public Sex Sex { get; set; }
            public bool Approved { get; set; }
    
            public static Person GetPerson()
            {
                Person person = new Person();
                person.ID = "1";
                person.FirstName = "John";
                person.LastName = "Last";
                person.DateOfBirth = new DateTime(1990, 1, 1);
                person.Sex = Sex.Male;
                person.Approved = true;
    
                return person;
            }
        }
    
        public enum Sex
        {
           Male,
           Female
        }
    // Controller

    public class SubmitController : Controller
        {
            public ActionResult Index()
            {
                return View(Person.GetPerson());
            }
    
            public ActionResult SuccessSubmit(Person person)
            {
                X.Msg.Alert("Submit", JSON.Serialize(person)).Show();
                return this.FormPanel(true);
            }
    
            public ActionResult FailureSubmit(FormCollection values)
            {
                var errors = new FieldErrors();
                
                foreach (var key in values.Keys)
                {
                    errors.Add(new FieldError(key.ToString(), "Test error for " + key.ToString()));
                }
    
                return this.FormPanel("Error is emulated", errors);
            }
    
            public ActionResult DirectEventSubmit(Person person)
            {
                X.Msg.Alert("Submit", JSON.Serialize(person)).Show();
                return this.Direct();
            }
        }

    //View

     @(
     Html.X().Window()
                .Title("Submit")
                .Width(250)
                .Height(220)
                .Layout(LayoutType.Fit)
                .Closable(false)
                .Border(false)
                .Items(
                    Html.X().FormPanel()
                        .ID("FormPanel1")
                        .Frame(true)
                        .DefaultAnchor("100%")
                        .BodyPadding(6)
                        .FieldDefaults(def =>
                        {
                            def.MsgTarget = MessageTarget.Side;
                        })
                        .Items(
                            Html.X().HiddenFor(m => m.ID),
                            Html.X().TextFieldFor(m => m.FirstName),
                            Html.X().TextFieldFor(m => m.LastName),
                            Html.X().DateFieldFor(m => m.DateOfBirth),
                            Html.X().ComboBoxFor(m => m.Sex).Listeners(ls=>ls.Change.Handler="alert('hi');"),
                            Html.X().CheckboxFor(m => m.Approved)
                        )
                )
                .Buttons(
                    Html.X().Button()
                        .Text("Submit variations")
                        .MenuItem(
                            Html.X().MenuItem().Text("FormPanel submit - Success").Handler("success"),
                            Html.X().MenuItem().Text("FormPanel submit - Failure").Handler("failure"),
                            Html.X().MenuItem()
                                .Text("DirectEvent submit")
                                .DirectEvents(de => {
                                    de.Click.Url = Url.Action("DirectEventSubmit");
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.FormID = "FormPanel1";
                                })
                        )
                )
        )
    Last edited by Daniil; Dec 13, 2013 at 5:57 AM. Reason: [CLOSED]
  2. #2
    Hi @PriceRightHTML5team,

    Please set up this setting for the ComboBox.
    .FireChangeOnLoad(false)

Similar Threads

  1. [CLOSED] DisplayField change event does not fire
    By amitpareek in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Feb 06, 2014, 3:16 AM
  2. [CLOSED] Model Binding POSTed combobox values
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Mar 09, 2012, 1:36 PM
  3. fire combobox's change event
    By jachnicky in forum 1.x Help
    Replies: 2
    Last Post: Dec 06, 2010, 4:33 PM
  4. Replies: 9
    Last Post: Nov 22, 2010, 4:06 AM
  5. [CLOSED] Change event on combobox doesn't fire
    By Stefanaccio in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 06, 2010, 5:01 PM

Posting Permissions