panther icon indicating copy to clipboard operation
panther copied to clipboard

Selecting a radio button with value "0" is not possible if another element is pre-selected

Open NicoHaase opened this issue 6 months ago • 1 comments

In a form in my project, a form holds two radio buttons for the field transfer with values 0 and 1. When the button with value 1 is pre-selected, I cannot change that. $form['transfer']->setValue('0'); does nothing, as Symfony\Component\Panther\WebDriver\WebDriverCheckbox::getRelatedElements does not yield any field selector when $value = '0'

I could get this working when modifing the first line of that method from

$valueSelector = $value ? sprintf(' and @value = %s', XPathEscaper::escapeQuotes($value)) : '';

to

$valueSelector = !is_null($value) ? sprintf(' and @value = %s', XPathEscaper::escapeQuotes($value)) : '';

NicoHaase avatar Jan 26 '24 10:01 NicoHaase

Bizarre - I've just chased down this exact same issue, and here it is top of the list :)

All I have to add is that it doesn't matter about pre-selected values. On a completely fresh form this bug also prevents me from selecting a checkbox/radio with a non-truthy value.

I had a ChoiceType form with two radios - {"Yes": "1", "No": "0"} - and trying to submit the form via Panther with {"confirm": "0"} ended up with it selecting "Yes" :D

(A workaround for my issue was to change my form to use the "choice_value" option to alter the strings that were being outputted on the HTML side whilst not changing the data values that the form returned via getData())

WubbleWobble avatar Feb 01 '24 17:02 WubbleWobble