Page 1 of 1

forced value to two Select fields hierarchically connected

Posted: Thu Feb 23, 2017 2:21 am
by jtandrea

hi All.

PHPMaker 12.0.7 here.

I have two Select fields, say: sField1, sField2 plus a Custom Field tChoice

sField1[0] = "Martin"
sField1[1] = "Taylor"
sField1[2] = "Gibson"

sField2[0] = "D28" ("Martin")
sField2[1] = "D35" ("Martin")
sField2[2] = "D41" ("Martin")
sField2[3] = "514" ("Taylor")
sField2[4] = "714" ("Taylor")
sField2[5] = "J45" ("Gibson")

When the user selects sField1 = "Taylor", sField2 is populated only by "514" and "714"
letting him choose between two values, say, 514.

What I want to accomplish, is to have user
to be able to write "514" in tChoice, to force in sField1 = "Taylor" and in sField2 = "514"

is it possible to do so?

Yes I populated both select controls using lookup table.

I tried putting myself known values (with javascript or jquery): onto sField1 succesfully, but it doesn't trigger any event (say click),
and onto sField2 with no luck (until sField2 hasn't inherited sField1 value, it doesn't contain any value at all).

any clue?

regards.


Re: forced value to two Select fields, hierarchically connec

Posted: Thu Feb 23, 2017 4:28 pm
by mobhar

Have you already tried "Dynamic Selection List" in PHPMaker? Please read about that topic from PHPMaker Help menu for more info and example.


Re: forced value to two Select fields, hierarchically connec

Posted: Thu Feb 23, 2017 6:44 pm
by jtandrea

actually I do use "Dynamic Selection List" option.

can you suggest any workaround to trigger the click event onto sField1 (with jquery forced value) so to populate sField2 ?


Re: forced value to two Select fields hierarchically connect

Posted: Fri Feb 24, 2017 12:02 am
by jtandrea

code below.

Server Events
Table-Specific
function Page_Load() {
ew_SetClientVar("MyCustomSqlSearchModel", ew_Encrypt("SELECT model, brandname from q_catalog where model='{query_value}'"));
}

Client Scripts
Add/Copy Page
Startup Script

//this is the tChoice field I mentioned before
$("#x_SEARCH_MODEL").change(function () {
var resultSearchModel = ew_Ajax(ewVar.MyCustomSqlSearchModel, $(this).val());
document.getElementById("x_BRANDNAME").value = resultSearchModel[1];
$("#x_BRANDNAME").val(resultSearchModel[1]); //works partially (value is ok but the x_brandname Select reacts as if it wasn't really selected)
$("#x_MODEL").val(resultSearchModel[0]); //doesn't work because x_model actually is empty (x_brandname didn't trigger click event)
});

regards


Re: forced value to two Select fields hierarchically connect

Posted: Sat Feb 25, 2017 12:06 am
by mobhar

Try change this:
$("#x_BRANDNAME").val(resultSearchModel[1]); //works partially (value is ok but the x_brandname Select reacts as if it wasn't really selected)
$("#x_MODEL").val(resultSearchModel[0]); //doesn't work because x_model actually is empty (x_brandname didn't trigger click event)

to:
$("#x_BRANDNAME").val(resultSearchModel[1]).change();
$("#x_MODEL").val(resultSearchModel[0]).change();


Re: forced value to two Select fields hierarchically connect

Posted: Sun Feb 26, 2017 5:06 pm
by jtandrea

hi mobhar, it worked perfectly! thanks very much.