1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-23 23:02:58 +02:00

Update InputfieldSelect::addOptionsString() to allow for user-defined disabled option if line in option string is prefixed with "disabled:"

This commit is contained in:
Ryan Cramer
2018-04-06 07:14:48 -04:00
parent c5147a5279
commit 9d11d87e9b

View File

@@ -119,14 +119,28 @@ class InputfieldSelect extends Inputfield {
$attrs = array(); $attrs = array();
$label = null; $label = null;
if(strpos($option, '++') === 0) {
// double plus should convert to single plus and not make it selected
$option = substr($option, 1);
} else if(substr($option, 0, 1) === '+') {
// if option starts with a plus then make it selected // if option starts with a plus then make it selected
if(substr($option, 0, 1) == '+') $attrs['selected'] = 'selected'; $attrs['selected'] = 'selected';
$option = ltrim($option, '+');
} else if(strpos($option, 'disabled:') === 0) {
// if option starts with "disabled:" then make it disabled
$attrs['disabled'] = 'disabled';
$option = preg_replace('/^disabled:\s*/', '', $option);
}
// option option has an equals "=", but not "==", then assume it's a: value=label if(strpos($option, '=') !== false && strpos($option, '==') === false) {
if(strpos($option, '=') !== false && strpos($option, '==') === false) list($option, $label) = explode('=', $option); // option has an equals "=", but not "==", then assume it's a: value=label
list($option, $label) = explode('=', $option);
}
if(strpos($option, '==') !== false) {
// convert double equals "==" to single equals "=", as a means of allowing escaped equals sign // convert double equals "==" to single equals "=", as a means of allowing escaped equals sign
if(strpos($option, '==') !== false) $option = str_replace('==', '=', $option); $option = str_replace('==', '=', $option);
}
$option = trim($option, '+ '); $option = trim($option, '+ ');
@@ -142,7 +156,9 @@ class InputfieldSelect extends Inputfield {
$lastOption = $option; $lastOption = $option;
} }
if($optgroupLabel && count($optgroup)) $this->addOption($optgroupLabel, $optgroup); if($optgroupLabel && count($optgroup)) {
$this->addOption($optgroupLabel, $optgroup);
}
return $this; return $this;
} }