PDA

View Full Version : [CLOSED] ComboBox Change Event get fire on binding with model value



PriceRightHTML5team
Dec 09, 2013, 2:58 PM
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";
})
)
)
)

Daniil
Dec 09, 2013, 3:52 PM
Hi @PriceRightHTML5team,

Please set up this setting for the ComboBox.

.FireChangeOnLoad(false)