Jump to content

set selected values for InputfieldAsmSelect in a custom process module


Orkun
 Share

Recommended Posts

how can I achieve something like this:

post-3125-0-35886000-1453214399_thumb.pn

in a custom process module ? I made a Interface(form) with the Inputfields components, but i don't know how to make the asmSelect to set the values so that it looks like above. At the Moment mine InputfieldAsmSelect looks like this in my alternative Interface:

post-3125-0-56499500-1453214879_thumb.pn

post-3125-0-09562400-1453214883_thumb.pn

Here's the code which I have so far:

$field = $this->modules->get("InputfieldAsmSelect");
$field->columnWidth = 50;
$field->label = __("Titel");
$field->attr("id+name",'titel');
$fieldsTitel = $this->fields->get('titel');
$options = $fieldsTitel->type->getOptions($fieldsTitel);
foreach ($options as $option) {
	$field->addOption($option->value, $option->title);
}
$valArray = array();
foreach ($entryPage->titel as $value) {
	$valArray[] .= $value->title;
}
$field->value = $valArray;
$form->append($field);  
Link to comment
Share on other sites

Your array look like have auto index. Try to set array key as $value->id if there is a id or something like it.
 
on here: $field->addOption($option->value, $option->title); you used $option->value like a key
but on here : $valArray[] .= $value->title; you don't have a key ? and when you set an array don't use .= this will be enought $valArray[] = $value->title;  or $valArray[$value->value] = $value->title; 

For asmSelect you can clone core asmSelect module and rename it modify module as your needs or if there hook available you can make hook or you can use asmSelect directly.

  • Like 1
Link to comment
Share on other sites

Usually it works if you just set the "$entryPage->titel" to the value, but think it only works with the ID.

Depends if you use the "ID" or the additional "value" options (id=value|title)

If using value:

foreach ($options as $option) {
    $field->addOption($option->value, $option->title);
}

foreach ($entryPage->titel as $value) {
    $valArray[] = $value->value; // array of values selected, not key=>title
}

$field->attr("value", $valArray);

Using ID

foreach ($options as $option) {
    $field->addOption($option->id, $option->title);
}

$field->attr("value", $entryPage->titel); // just passing the field (only when outputformatting off)

If that doesn't work just make an array using id.

foreach ($entryPage->titel as $value) {
    $valArray[] = $value->id; 
}
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...