Set field as require based in another field's change

374 Views Asked by At

I have a DevExtreme form with Razor and I'm trying to apply validation rules. I want to set field as required when another field has value.

// This should have a value if the other field has it
socialGroup.AddSimple()
           .ColSpan(3)
           .Label(l => l.Text("Page ID"))
           .DataField(it.Clave)
           .Editor(ed => ed.TextBox().ID("pageId").Value(it.Valor).Placeholder("Page ID"))
           .ValidationRules(v => v.AddPattern().Pattern("^\\d+$").Message("Field must be numeric"));

// This should have a value if the other field has it
socialGroup.AddSimple()
           .ColSpan(3)
           .Label(l => l.Text("App ID"))
           .DataField(it.Clave)
           .Editor(ed => ed.TextBox().ID("appId").Value(it.Valor).Placeholder("App ID"))
           .ValidationRules(v => v.AddPattern().Pattern("^\\d+$").Message("Field must be numeric"));

I've tried with Javascript but couldn't make it work.

0

There are 0 best solutions below