diff --git a/wire/core/Field.php b/wire/core/Field.php index 790fef82..cd986316 100644 --- a/wire/core/Field.php +++ b/wire/core/Field.php @@ -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); diff --git a/wire/core/InputfieldWrapper.php b/wire/core/InputfieldWrapper.php index 5f4a4ed9..d5969469 100644 --- a/wire/core/InputfieldWrapper.php +++ b/wire/core/InputfieldWrapper.php @@ -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])) {