1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 15:57:01 +02:00

Add support for matching data attributes in show-if conditions. Also updated FieldtypeOptions to add data-if-value attribute to select <option> tags as a way use it. This attribute contains the option value (when separate option values and labels are used). This enables you to match by value rather than by option ID. Example show-if selector: colors.data-if-value=blue. Previously you could only match by option ID, i.e. colors=123. Maybe we'll add something similar for page refernce fields so that you can match by page name or path, rather than by ID.

This commit is contained in:
Ryan Cramer
2024-09-13 13:29:09 -04:00
parent 754b1fffb7
commit 965f956bc3
4 changed files with 21 additions and 6 deletions

View File

@@ -105,7 +105,10 @@ class FieldtypeOptions extends FieldtypeMulti implements Module {
if(!$inputfield) $inputfield = $this->wire()->modules->get('InputfieldSelect');
foreach($this->manager->getOptions($field) as $option) {
$inputfield->addOption((int) $option->id, $option->getTitle());
$value = $option->value;
$attrs = [];
if($value) $attrs['data-if-value'] = $value;
$inputfield->addOption((int) $option->id, $option->getTitle(), $attrs);
}
if($field->get('initValue')) {