Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Form - Cascade List - Ajax


Go to End


757 Views

Avatar
Tia

Community Member, 2 Posts

1 October 2014 at 7:13pm

I want user to choose Jabatan first then, list of Unit will be display based on chosen Jabatan. Both Jabatn n Unit get from database. Im still working on it. Tried several code, but its not working.
This code is working fine but the Unit is already displayed without depending on Jabatan. This is not what i one.
Anyone.. could u pls help? Been working to get this working since last week.

<td>Jabatan*</td>
<td>:</td>
<td><?php
$selObj = new Select('jabatan', 'jabatan');
$selObj->addOption('', '---SILA PILIH--');
$selObj->setDataSource($DBQueryObj); //Check DBQuery object is correct.
$selObj->setDataSourceTableAdv('_kod_jabatan', 'kod_jab', 'perihal');
//$selObj->setFilterColumnAdv('COLUMN_NAME', 'FILTER VALUE', IFieldType::STRING_TYPE, IConditionOperator::NONE); //Comment if not using filter.
$selObj->setSortColumnAdv(ISortColumn::COLUMN_LABEL, ISortOrder::ASC);
$selObj->initBindingSelectAdv();
$selObj->setSelectedValue($jabatan); //Change default value.
$selField = $selObj->renderField();
echo $selField['fieldHTML'];
?></td>
</tr>
<tr>
<td>Unit*</td>
<td>:</td>
<td><?php
$selObj = new Select('unit', 'unit');
$selObj->addOption('', '---SILA PILIH--');
$selObj->setDataSource($DBQueryObj); //Check DBQuery object is correct.
$selObj->setDataSourceTableAdv('_kod_unit', 'kod', 'perihal');
//$selObj->setFilterColumnAdv('COLUMN_NAME', 'FILTER VALUE', IFieldType::STRING_TYPE, IConditionOperator::NONE); //Comment if not using filter.
$selObj->setSortColumnAdv(ISortColumn::COLUMN_LABEL, ISortOrder::ASC);
$selObj->initBindingSelectAdv();
$selObj->setSelectedValue($unit); //Change default value.
$selField = $selObj->renderField();
echo $selField['fieldHTML'];
?></td>
</tr>