formers / former

A powerful form builder, for Laravel and other frameworks (stand-alone too)
https://formers.github.io/former/
1.34k stars 204 forks source link

Multiple attributes treated differently from single attribute in queryToArray #583

Open OXINARF opened 5 years ago

OXINARF commented 5 years ago

https://github.com/formers/former/blob/d8cf68fce36770646237ce92d7cf86576c1bdebf/src/Former/Helpers.php#L188-L193

This code forces the string type:

It was detected when adding a new attribute to select options, which until then only had the typical value. When populating the default selected option, it would fail because the populated value was an int but the value was now a string. I workaround it by casting the default selected value to a string when calling populateField, but it would be better to fix Former.

Proposed fix:

//For backward compatibility 
if (count($attributes) === 1) { 
    $array[$optionAttributeValue] = (string) $optionText; 
} else { 
    $array[(string) $optionText][$optionAttributeName] = $optionAttributeValue; 
} 

P.S.: I only come into contact with Former through another project so I might be completely missing something here, my apologies if so.