File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -55,22 +55,32 @@ public function parseField(): mixed
5555 $ preppedData = [];
5656
5757 $ options = Hash::get ($ this ->field , 'settings.options ' );
58+ $ customOptions = Hash::get ($ this ->field , 'settings.customOptions ' , false );
5859 $ match = Hash::get ($ this ->fieldInfo , 'options.match ' , 'value ' );
5960
6061 foreach ($ options as $ option ) {
61- foreach ($ value as $ dataValue ) {
62+ foreach ($ value as $ key => $ dataValue ) {
6263 if ($ dataValue === $ option [$ match ]) {
6364 $ preppedData [] = $ option ['value ' ];
65+ unset($ value [$ key ]);
6466 }
6567
6668 // special case for when mapping by label, but also using a default value
6769 // which relies on $option['value']
6870 if (empty ($ dataValue ) && in_array ($ option ['value ' ], $ default )) {
6971 $ preppedData [] = $ option ['value ' ];
72+ unset($ value [$ key ]);
7073 }
7174 }
7275 }
7376
77+ // if custom options are allowed, and we still have values left in the $value variable - process those too
78+ if ($ customOptions && !empty ($ value )) {
79+ foreach ($ value as $ dataValue ) {
80+ $ preppedData [] = $ dataValue ;
81+ }
82+ }
83+
7484 return $ preppedData ;
7585 }
7686}
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ public function parseField(): mixed
5151 $ default = Hash::get ($ this ->fieldInfo , 'default ' );
5252
5353 $ options = Hash::get ($ this ->field , 'settings.options ' );
54+ $ customOptions = Hash::get ($ this ->field , 'settings.customOptions ' , false );
5455 $ match = Hash::get ($ this ->fieldInfo , 'options.match ' , 'value ' );
5556
5657 foreach ($ options as $ option ) {
@@ -62,7 +63,8 @@ public function parseField(): mixed
6263 }
6364 }
6465
65- if (empty ($ value )) {
66+ // if value is empty or the field supports adding custom options - return the value
67+ if (empty ($ value ) || $ customOptions ) {
6668 return $ value ;
6769 }
6870
You can’t perform that action at this time.
0 commit comments