Commit
New feature: Default value for yes/no question type
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* | ||
* This file holds the widget for the yes-no question type, to edit it's default values. | ||
* | ||
* Features: | ||
* - YES/NO preselection | ||
* - EM integration to insert an em expression like {TOKEN:ATTRIBUTE_6}. At this state there is no validation implemented. Attributes must hold Y or N. | ||
* | ||
* DEV MEMO: | ||
* Validation could be difficult cause if you using tokens and you don't had setup a working token dataset | ||
* | ||
* For this feature you need editDefaultvalues.php, database.php, adminstyle.css | ||
*/ | ||
|
||
class yesNo_defaultvalue_widget extends CWidget | ||
{ | ||
public $widgetOptions; | ||
|
||
//init() method is called automatically before all others | ||
public function init() | ||
{ | ||
/*you can set initial default values and other stuff here. | ||
* it's also a good place to register any CSS or Javascript your | ||
* widget may need. */ | ||
|
||
} | ||
|
||
public function run() | ||
{ | ||
|
||
$qtproperties = $this->widgetOptions['qtproperties']; | ||
$questionrow = $this->widgetOptions['questionrow']; | ||
$langopts = $this->widgetOptions['langopts']; | ||
$language = $this->widgetOptions['language']; | ||
$defaultValues = $this->widgetOptions['langopts'][$language][$questionrow['type']][0]; | ||
$clang = $this->widgetOptions['clang']; | ||
|
||
$emfield_css = ''; | ||
$emValue = ''; | ||
$select = ''; | ||
$sEmfield_css_class = ''; | ||
|
||
// prepare variables for prefilling the form | ||
if(!is_null ($defaultValues)) | ||
{ | ||
$sDefaultValue = $defaultValues; | ||
if(($sDefaultValue == 'N') || ($sDefaultValue == 'Y') || ($sDefaultValue == '') ){ //|| 'Y' || NULL)){ | ||
$select = $defaultValues; | ||
}else{ | ||
$select = 'EM'; | ||
$emValue = $defaultValues; | ||
} | ||
} | ||
|
||
if($questionrow['type'] == 'Y') // do we need this? | ||
{ | ||
$sElement_id = 'defaultanswerscale_0_' . $language; | ||
|
||
$aList = array( | ||
'N' => $clang->gT('No'), | ||
'Y' => $clang->gT('YES'), | ||
'EM' => $clang->gT('EM Value') | ||
); | ||
|
||
$aHtmlOptions = array( | ||
'empty' => $clang->gT('<No default value>'), | ||
'class' => $sElement_id, | ||
'onchange' => '// show EM Value Field | ||
if ($(this).val() == "EM"){ | ||
$("#"+$(this).closest("select").attr("id")+ "_EM").removeClass("hide"); | ||
}else{ | ||
$("#"+$(this).closest("select").attr("id")+ "_EM").addClass("hide");} ' | ||
); | ||
|
||
echo '<li>'; | ||
echo CHtml::dropDownList($sElement_id, $select, $aList, $aHtmlOptions); | ||
|
||
// textfield preparation | ||
if(empty($defaultValues) || $defaultValues == 'Y') | ||
{ | ||
$sEmfield_css_class = 'hide'; | ||
} | ||
echo CHtml::textField ($sElement_id . '_EM', $emValue,array( | ||
'id' => $sElement_id . '_EM', | ||
'class' => $sEmfield_css_class, | ||
'width' => 100 | ||
)); | ||
echo '</li>'; | ||
} | ||
} | ||
} |
4 comments
on commit f51d66a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question about default_value with EM : it can work only with a GUI ?
I you put for a list : {if(QCODE=="Y","A1","A2)} in default value for a list via phpMyAdmin, it work ?
If yes : this can be in 2.06 or 2.05 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at the patch. It is supposed to do this - at least for the Yes/No question. Since the functionality did not exist before and has no effect on existing code it was merged to 2.05
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but looking at code, i think same think can be applied without updating qanda and/or EM. Then think we can do it for all actual question tye with default value :) .
See : 09eaf5e :)
I think we can replace by /application/config/config.php ?