?
avatar brianteeman
brianteeman
2 Nov 2018

Steps to reproduce the issue

add 2 "checkbox" fields to any joomla form as below

	<field 
		name="checkboxnovalue" 
		type="checkbox" 
		label="chekbox1" 
	/>
	<field 
		name="checkboxcustomvalue"
		 type="checkbox" 
		 label="checkbox2" 
		 value="CUSTOM"
	/>

Expected result

  1. When saving a form with neither box checked the value in the db will be blank
  2. When saving a form with both checked the values in the db will be "1" and "CUSTOM"

Actual result

  1. values stored as 0
  2. values stored as "On" and "CUSTOM"

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value

The value attribute is one which all inputs share; however, it serves a special purpose for inputs of type checkbox: when a form is submitted, only checkboxes which are currently checked are submitted to the server, and the reported value is the value of the value attribute. If the value is not otherwise specified, it is the string "on" by default.

avatar brianteeman brianteeman - open - 2 Nov 2018
avatar joomla-cms-bot joomla-cms-bot - change - 2 Nov 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 2 Nov 2018
avatar Bakual
Bakual - comment - 2 Nov 2018

Checkboxes are a funny thing. The way they work is that if unchecked, the browser will not send anything. If checked, the value is sent. Thus in Joomla, we have no way to check if the checkbox isn't sent because it was unchecked or because it wasn't there at all (due to overrides or custom field conditionals or ...). That's probably why an unchecked box will appear blank.

As for the stored value, I think that could be changed to "on" for sure. But honestly I think "1" works better in PHP since you can evaluate it better, "on" is just a string without any special meaning in a computer language. Is there a reason you want it to be "on" (beside it is the actual value sent)?

Ignore that, was reading the issue 180° wrong.

avatar brianteeman
brianteeman - comment - 2 Nov 2018

Checkboxes are a funny thing. The way they work is that if unchecked, the browser will not send anything.

So we should be storing nothing not a 0

That's probably why an unchecked box will appear blank.
As it should be but we store a value in the db of 0

I dont care about it being stored as On or 1
I do care that if checked and a value is defined then it should be stored in the db

avatar brianteeman
brianteeman - comment - 2 Nov 2018

Or am I misunderstanding it.

avatar SharkyKZ
SharkyKZ - comment - 2 Nov 2018

values stored as 0

Can't confirm this. If you're storing these fields in their own DB columns, maybe the columns have a default value of 0?

values stored as "On"

Can't confirm this either. Which form did you edit?

and "CUSTOM"

For this change value="CUSTOM" to default="CUSTOM". See #22575.

avatar Bakual
Bakual - comment - 2 Nov 2018

@brian: Nah, I misunderstood your issue. I've read it the wrong way around. Sorry.

avatar brianteeman
brianteeman - comment - 2 Nov 2018

@SharkyKZ I added them to the module custom options and they were stored in JSON with a 0

Setting default to get the value instead of setting value makes no sense to me and doesn't match the documentation or behaviour of any other field type

avatar brianteeman brianteeman - change - 2 Nov 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-11-02 17:56:59
Closed_By brianteeman
avatar brianteeman brianteeman - close - 2 Nov 2018

Add a Comment

Login with GitHub to post a comment