joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Add support ID with 0 for value CheckboxField.php

Open korenevskiy opened this issue 3 years ago • 8 comments

This amendment concerns to use this field to pass ID as an argument. If we use this field not in an XML file but in a dynamic table of fields. In each row of the table, we use the Checkbox to select a row number or select an ID in the list. After activating these checkboxes, we mark which of the parameter lists with which ID we have activated. I believe that the original code implied the use of checkboxes as just a parameter in the static configuration of the settings page, not to select an ID, but simply to select certain settings. Therefore, such a subtlety as using the value '0' as a value was not taken into account. My change does not violate compatibility and does not violate the default settings. And of course it would be stupid on the part of external developers to use the value '0' of the attribute to get an activated checkbox. Because the value '0' is interpreted as an empty value and we get an active checkbox. In this way, it is stupid to mark activity using unreadable, this is a stupid approach to activate the checkbox. Therefore, I suggest using the value '0' as the value for ID selection.

$field = JFormHelper::loadFieldType('сheckbox', true);
$field->setup(simplexml_load_string('<field type="check" default="0"  name="id" />', 0);
echo $field->getInput();

The result can only be seen in the generated HTML. Because of this limitation of fields, we can't check in any other way, except to look for values in HTML. Before:

<div class="form-check form-check-inline">
	<input
		type="checkbox"
		name="check"
		id="id"
		value="1"
	>
</div>

After:

<div class="form-check form-check-inline">
	<input
		type="checkbox"
		name="check"
		id="id"
		value="0" 
	>
</div>

Here you need to search for the string value ="0" with tests, otherwise no way. In the Checkbox field, any default value is rendering correctly except for 0. The default value of 0 is rendering as 1. This fix can be checked in any module add writing this XML example to the module’s XML configuration file and after check this value in the F12 panel in the browser .

<field 
	name="id"
	type="checkbox"  
	label="Test value 0 in Checkbox!!!"  
	default="0" />

korenevskiy avatar Mar 02 '22 15:03 korenevskiy

Thanks for your pull request. Please add a proper test instruction, so we can test it.

laoneo avatar Mar 19 '22 13:03 laoneo

Thanks for your pull request. Please add a proper test instruction, so we can test it.

I can't find the Checkbox field test file. I'm new to writing tests. Previously, I wrote only 2 amendments to Joomla tests. Please tell me where I can find the Checkbox field test.

korenevskiy avatar Mar 22 '22 21:03 korenevskiy

Please provide steps to reproduce the issue in order to test the PR.

Quy avatar Mar 22 '22 21:03 Quy

$field = JFormHelper::loadFieldType('сheckbox', true);
$field->setup(simplexml_load_string('<field type="check" default="0"  name="id" />', 0);
echo $field->getInput();

The result can only be seen in the generated HTML. Because of this limitation of fields, we can't check in any other way, except to look for values in HTML. Before:

<div class="form-check form-check-inline">
	<input
		type="checkbox"
		name="check"
		id="id"
		value="1"
	>
</div>

After:

<div class="form-check form-check-inline">
	<input
		type="checkbox"
		name="check"
		id="id"
		value="0" 
	>
</div>

Here you need to search for the string value ="0" with tests, otherwise no way. In the Checkbox field, any default value is rendering correctly except for 0. The default value of 0 is rendering as 1.

korenevskiy avatar Mar 22 '22 21:03 korenevskiy

When you have a look at #37349, there you can see some test instructions how it should be. If the tester has to edit some files, write that in the testing instructions. That's not a problem.

laoneo avatar Mar 23 '22 07:03 laoneo

When you have a look at #37349, there you can see some test instructions how it should be. If the tester has to edit some files, write that in the testing instructions. That's not a problem.

You are right, I understood my mistake. I described a new correction indicating the perimers on the principle: as it was before, and how it will become in the future. I added a description of the PR header .

korenevskiy avatar May 15 '22 12:05 korenevskiy

This pull request has automatically rebased to 4.2-dev.

HLeithner avatar Jun 27 '22 13:06 HLeithner

This pull requests has been automatically converted to the PSR-12 coding standard.

joomla-bot avatar Jun 27 '22 21:06 joomla-bot

This pull request has been automatically rebased to 4.3-dev.

HLeithner avatar May 02 '23 16:05 HLeithner

@HLeithner Is it possible to transfer this PR to Joomla 5 ?

korenevskiy avatar Jul 13 '23 08:07 korenevskiy

This is a bug, and can go to 4.x, just need to be tested

Fedik avatar Jul 13 '23 08:07 Fedik

I have tested this item :white_check_mark: successfully on 6fd6fcb03abb2e18f66c8319320d36df405ad2ec


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/37174.

Fedik avatar Jul 13 '23 09:07 Fedik

I have tested this item :white_check_mark: successfully on 8b05ef3365f0303c0d226e1d9ada114720310805


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/37174.

Fedik avatar Jul 13 '23 13:07 Fedik

@Fedik How do you think if we set the Default field to FALSE, how should it work? And probably we think about in which cases it may turn out that we will need to specify the value FALSE.

<field type="check" default="false"  name="id" />

korenevskiy avatar Jul 14 '23 09:07 korenevskiy

HTML supports only string value, so no boolean values. You cannot do <input type="checkbox" value="false"> and expect it will be a boolean, it will be a string false. The same for Joomla XML fields. so only 1 or 0

Fedik avatar Jul 14 '23 10:07 Fedik

so only 1 or 0

You are right, this will be enough for all use cases.

korenevskiy avatar Jul 14 '23 10:07 korenevskiy

@bembelimen Please confirm this PR

korenevskiy avatar Aug 10 '23 19:08 korenevskiy

This pull request has been automatically rebased to 4.4-dev.

HLeithner avatar Sep 30 '23 22:09 HLeithner

@HLeithner And when will this PR be merged to v5?

korenevskiy avatar Dec 27 '23 00:12 korenevskiy