CMS MADE SIMPLE FORGE

Form Builder

 

[#12417] CSS class for Check Box not being applied to input tag

avatar
Created By: Christine Collen (ccollen)
Date Submitted: Tue Feb 16 13:02:59 -0500 2021

Assigned To:
Version: 1.1
CMSMS Version: 2.2.13
Severity: Minor
Resolution: Awaiting Response
State: Open
Summary:
CSS class for Check Box not being applied to input tag
Detailed Description:
I noticed that the CSS class field on the advanced setting tab for check box
type field was being ignored in the rendered form code.
I took a look at the class file CheckBoxField.class.php and saw the problem at
line 45 in the GetFieldInput function which is calling the CreateInputCheckbox
method of the (deprecated) CMS Module class.

This does not include the CSS class value at all.  And I noticed another problem
when I was trying to overcome this by manually generating the checkbox input tag
- it did not remember its setting if there were invalid fields present on the
form.

I have done a major hack on this GetFieldInput function code so that the class
property is included as well as overcoming the problem about remembering if it
was previously checked.

I suspect there is a similar problem in the CheckboxGroupField.class.php and
CheckboxExtendedField.class.php as they are both using the CreateInputCheckbox
method.

Also, there is a function in the class.formbuilder_utils.php which I suspect is
not used:
lines 185-209 function create_input_checkbox ...

So, here is my complete hack for the GetFieldInput function, including some
commented-out debugging lines at end:

function GetFieldInput($id, &$params, $returnid)
	{
		$mod = formbuilder_utils::GetFB();
		$label = '';
		$html5 = '';
		$checked = '';
		$js = $this->GetOption('javascript','');
		$css_class = $this->GetOption('css_class');
		$cssid = $this->GetCSSId();
		$name = $id.'fbrp__'.$this->Id;		

		if ($this->GetOption('html5','0') == '1'&& $this->IsRequired())
		{
			$html5 = ' required';
		}
		if (strlen($this->GetOption('label','')) > 0)
			{
$label = '&nbsp;<label
for="'.$cssid.'">'.$this->GetOption('label').'</label>';
			}
if ( ($this->Value === false && $this->GetOption('is_checked','0')=='1') ||
$this->Value == $this->GetOption('checked_value','0') )
			{
			$this->Value = $this->GetOption('checked_value');
			$checked = ' checked="checked"';
			}
					
$text = '<input type="checkbox" class="'.$css_class.'" name="'.$name.'"
id="'.$cssid.'" value="'.$this->GetOption('checked_value').'"'.$checked;
    	$text .= " />\n";
		/* for debugging*/
		/*
		echo "Checked value is : ".$this->GetOption('checked_value').'<br>';
		echo "Unchecked value is : ".$this->GetOption('unchecked_value').'<br>';
		echo "Option - is_checked : ".$this->GetOption('is_checked','0').'<br>';
		echo "Value is : ".$this->Value;		
		*/	
		return $text.$label;		
	}


History

Comments
avatar
Date: 2021-02-17 08:02
Posted By: Rolf (rolf1)

Thanks for your report and fix suggestion, we have looked into it.

The current situation works though but in a different way… The provided class is
added to a wrapper div and *not* to the input field itself. Changing this would
probably break the styling at other sites.
It is as design as per the original developer intentions, and we are refactoring
the field PHP classes for future versions to not only make FormBuilder more
versatile, but also keep backwards compatibility as much as possible.
So we won't fix it at the moment as there are ways to work around that in the
template and stylesheet without having to hack the PHP code, in example:

.provided_class input[type="checkbox”] { ... }

See also https://cmscanbesimple.org/blog/styling-forms
      
Updates

Updated: 2021-02-17 08:02
resolution_id: => 10