mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 00:37:02 +02:00
Add support for a data-field-name attribute on Inputfields that use names that differ from the relevant field name (likes inputfields in repeaters). This makes the source field discoverable from JS in cases where it previously wasn't.
This commit is contained in:
@@ -978,6 +978,10 @@ class Field extends WireData implements Saveable, Exportable {
|
||||
// predefined field settings
|
||||
$inputfield->attr('name', $this->name . $contextStr);
|
||||
$inputfield->set('label', $this->label);
|
||||
if($contextStr) {
|
||||
// keep track of original field name in Inputfields that are are renamed by context
|
||||
if(!$inputfield->attr('data-field-name')) $inputfield->attr('data-field-name', $this->name);
|
||||
}
|
||||
|
||||
// just in case an Inputfield needs to know its Fieldtype/Field context, or lack of it
|
||||
$inputfield->set('hasFieldtype', $this->type);
|
||||
|
@@ -937,6 +937,12 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
|
||||
if(!isset($ffAttrs['id'])) $ffAttrs['id'] = 'wrap_' . $inputfield->attr('id');
|
||||
$ffAttrs['class'] = str_replace('Inputfield_ ', '', $ffAttrs['class']);
|
||||
$wrapClass = $inputfield->getSetting('wrapClass');
|
||||
$fieldName = $inputfield->attr('data-field-name');
|
||||
if($fieldName && $fieldName != $inputfield->attr('name')) {
|
||||
// ensures that Inputfields renamed by context retain the original field-name based class
|
||||
$wrapClass = "Inputfield_$fieldName $wrapClass";
|
||||
if(!isset($ffAttrs['data-id'])) $ffAttrs['data-id'] = "wrap_Inputfield_$fieldName";
|
||||
}
|
||||
if($wrapClass) $ffAttrs['class'] = trim("$ffAttrs[class] $wrapClass");
|
||||
foreach($inputfield->wrapAttr() as $k => $v) {
|
||||
if($k === 'class' && !empty($ffAttrs[$k])) {
|
||||
|
Reference in New Issue
Block a user