diff --git a/wire/core/Inputfield.php b/wire/core/Inputfield.php index db7c48e3..9b396f32 100644 --- a/wire/core/Inputfield.php +++ b/wire/core/Inputfield.php @@ -97,7 +97,7 @@ * =================== * @property int|bool $required Set to true (or 1) to make input required, or false (or 0) to make not required (default=0). #pw-group-behavior * @property string $requiredIf Optional conditions under which input is required (selector string). #pw-group-behavior - * @property int|bool|null $requiredAttr Use HTML5 “required” attribute when used by Inputfield and $required is true? Default=null. #pw-group-behavior + * @property int|bool|null $requiredAttr Use HTML5 “required” attribute when used by Inputfield and $required is true? Default=null. #pw-group-behavior * @property InputfieldWrapper|null $parent The parent InputfieldWrapper for this Inputfield or null if not set. #pw-internal * @property null|bool|Fieldtype $hasFieldtype The Fieldtype using this Inputfield, or boolean false when known not to have a Fieldtype, or null when not known. #pw-group-other * @property null|Field $hasField The Field object associated with this Inputfield, or null when not applicable or not known. #pw-group-other @@ -106,10 +106,12 @@ * @property bool|null $useLanguages When multi-language support active, can be set to true to make it provide inputs for each language, where supported (default=false). #pw-group-behavior * @property null|bool|int $entityEncodeLabel Set to boolean false to specifically disable entity encoding of field header/label (default=true). #pw-group-output * @property null|bool $entityEncodeText Set to boolean false to specifically disable entity encoding for other text: description, notes, etc. (default=true). #pw-group-output + * @property int $renderFlags Options that can be applied to render, see "render*" constants (default=0). #pw-group-output 3.0.204+ * @property int $renderValueFlags Options that can be applied to renderValue mode, see "renderValue" constants (default=0). #pw-group-output * @property string $wrapClass Optional class name (CSS) to apply to the HTML element wrapping the Inputfield. #pw-group-other * @property string $headerClass Optional class name (CSS) to apply to the InputfieldHeader element #pw-group-other * @property string $contentClass Optional class name (CSS) to apply to the InputfieldContent element #pw-group-other + * @property string $addClass Formatted class string letting you add class to any of the above (see addClass method). #pw-group-other 3.0.204+ * @property int|null $textFormat Text format to use for description/notes text in Inputfield (see textFormat constants) #pw-group-output * * @method string|Inputfield required($required = null) Get or set required state. @since 3.0.110 #pw-group-behavior @@ -299,6 +301,20 @@ abstract class Inputfield extends WireData implements Module { * */ const textFormatMarkdown = 8; + + /** + * Render flags: place first in render + * #pw-group-render-constants + * + */ + const renderFirst = 1; + + /** + * Render flags: place last in render + * #pw-group-render-constants + * + */ + const renderLast = 2; /** * Render only the minimum output when in "renderValue" mode. @@ -401,7 +417,9 @@ abstract class Inputfield extends WireData implements Module { $this->set('wrapClass', ''); // optional class to apply to the Inputfield wrapper (contains InputfieldHeader + InputfieldContent) $this->set('headerClass', ''); // optional class to apply to InputfieldHeader wrapper $this->set('contentClass', ''); // optional class to apply to InputfieldContent wrapper + $this->set('addClass', ''); // space-separated classes to add, optionally specifying element (see addClassString method) $this->set('textFormat', self::textFormatBasic); // format applied to description and notes + $this->set('renderFlags', 0); // See render* constants $this->set('renderValueFlags', 0); // see renderValue* constants, applicable to renderValue mode only $this->set('prependMarkup', ''); // markup to prepend to Inputfield output $this->set('appendMarkup', ''); // markup to append to Inputfield output @@ -479,17 +497,32 @@ abstract class Inputfield extends WireData implements Module { * */ public function set($key, $value) { - if($key == 'parent' && ($value instanceof InputfieldWrapper)) return $this->setParent($value); - if($key == 'collapsed') { + + if($key === 'parent') { + if($value instanceof InputfieldWrapper) return $this->setParent($value); + + } else if($key === 'collapsed') { if($value === true) $value = self::collapsedYes; $value = (int) $value; - } - if(array_key_exists($key, $this->attributes)) return $this->setAttribute($key, $value); - if($key == 'required' && $value && !is_object($value)) $this->addClass('required'); - if($key == 'columnWidth') { + + } else if(array_key_exists($key, $this->attributes)) { + return $this->setAttribute($key, $value); + + } else if($key === 'required' && $value && !is_object($value)) { + $this->addClass('required'); + + } else if($key === 'columnWidth') { $value = (int) $value; if($value < 10 || $value > 99) $value = ''; + + } else if($key === 'addClass') { + if(is_string($value) && !ctype_alnum($value)) { + $test = str_replace(array(' ', ':', ',', '-', '_', '.', '@', "\n"), '', $value); + if(!ctype_alnum($test)) $value = preg_replace('![^-_:@,. a-zA-Z0-9\n]!', '', $value); + } + $this->addClass($value); } + return parent::set($key, $value); } @@ -989,7 +1022,7 @@ abstract class Inputfield extends WireData implements Module { /** * Add a class or classes to this Inputfield (or a wrapping element) * - * If given a class name that's already present, it won't be added again. + * If given a class name that’s already present, it won’t be added again. * * ~~~~~ * // Add class "foobar" to input element @@ -1000,14 +1033,39 @@ abstract class Inputfield extends WireData implements Module { * * // Add class "foobar" to .Inputfield wrapping element * $inputfield->addClass('foobar', 'wrapClass'); + * + * // Add classes while specifying Inputfield element (3.0.204+) + * $inputfield->addClass('wrap:card, header:card-header, content:card-body'); * ~~~~~ * + * **Formatted string option (3.0.204+):** + * Classes can be added by formatted string that dictates what Inputfield element they + * should be added to, in the format `element:classNames` like in this example below: + * ~~~~~ + * wrap:card card-default + * header:card-header + * content:card-body + * input:form-input input-checkbox + * ~~~~~ + * Each line represents a group containing an element name and one or more space-separated + * classes. Groups may be separated by newline (like above) or with a comma. The element + * name may be any one of the following: + * + * - `wrap`: The .Inputfield element that wraps the header and content + * - `header`: The .InputfieldHeader element, typically a `