Skip to content

Commit

Permalink
show select and radio option value on confirm screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ichikaway committed Feb 24, 2010
1 parent 02fa369 commit 124b5d9
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions xform.php
Expand Up @@ -141,7 +141,6 @@ function __construct($config = null) {
}

function input($fieldName, $options = array()) {

$options = array_merge($this->inputDefaultOptions, $options);

return parent::input($fieldName, $options);
Expand Down Expand Up @@ -254,19 +253,19 @@ function text($fieldName) {
return call_user_func_array( array($this, 'parent::text'), $args);
}

function radio($fieldName) {
function radio($fieldName, $options = null) {
if($this->checkConfirmScreen()) {
return $this->getConfirmInput($fieldName);
return $this->getConfirmInput($fieldName, $options);
}
$args = func_get_args();
return call_user_func_array( array($this, 'parent::radio'), $args);

}


function select($fieldName) {
function select($fieldName, $options = null) {
if($this->checkConfirmScreen()) {
return $this->getConfirmInput($fieldName);
return $this->getConfirmInput($fieldName, $options);
}
$args = func_get_args();
return call_user_func_array( array($this, 'parent::select'), $args);
Expand Down Expand Up @@ -311,13 +310,21 @@ function _confirmValueOutput($data) {
}


function _getFieldData($fieldName) {
function _getFieldData($fieldName, $options = null) {
$modelname = current($this->params['models']);

// for Model.field pattern
$model_field = explode('.', $fieldName);
if(!empty($model_field[1])) {

if(!empty($model_field[1]) && !empty($this->data[$model_field[0]])) {
$fieldName = $model_field[1];

}else if(!empty($model_field[0])) {
$fieldName = $model_field[0];
}


if(!empty($model_field[1]) && !empty($this->data[$model_field[0]])) {
$data = $this->data[$model_field[0]];

}else{
Expand All @@ -332,19 +339,24 @@ function _getFieldData($fieldName) {
return false;
}

return $data;
return $data[$fieldName];
}



function getConfirmInput($fieldName) {
function getConfirmInput($fieldName, $options = null) {

if($data = $this->_getFieldData($fieldName)) {
if($data = $this->_getFieldData($fieldName, $options)) {

if(is_array($data[$fieldName])) {
$out = join($this->confirmJoinSeparator, $data[$fieldName]);
if(is_array($data)) {
if(is_array($options)) {
foreach($data as $key => $val) {
$data[$key] = (!empty($options[$val])) ? $options[$val] : $val;
}
}
$out = join($this->confirmJoinSeparator, $data);
}else {
$out = $data[$fieldName];
$out = (is_array($options) && !empty($options[$data])) ? $options[$data] : $data;
}
return $this->_confirmValueOutput($out);
}
Expand All @@ -355,9 +367,9 @@ function getConfirmInput($fieldName) {

function getConfirmDatetime($fieldName, $options = array()) {
if($data = $this->_getFieldData($fieldName)) {
if(is_array($data[$fieldName])) {
if(is_array($data)) {
$nothing = true;
foreach($data[$fieldName] as $key => $val) {
foreach($data as $key => $val) {
if(!empty($val)){
$nothing = false;
}
Expand Down Expand Up @@ -390,19 +402,19 @@ function getConfirmDatetime($fieldName, $options = array()) {


foreach($datefmt as $key => $val) {
$out .= (isset($data[$fieldName][$key]) ? $data[$fieldName][$key] . $val : '');
$out .= (isset($data[$key]) ? $data[$key] . $val : '');
}
if(!empty($options[2]) && $options[2] !== 'NONE') {
$out .= ' ';
foreach($timefmt as $key => $val) {
$sprintf_fmt = (isset($data[$fieldName][$key]) && is_numeric($data[$fieldName][$key])) ? '%02d' :'%s';
$out .= (isset($data[$fieldName][$key]) ? sprintf($sprintf_fmt ,$data[$fieldName][$key]) .$val : '');
$sprintf_fmt = (isset($data[$key]) && is_numeric($data[$key])) ? '%02d' :'%s';
$out .= (isset($data[$key]) ? sprintf($sprintf_fmt ,$data[$key]) .$val : '');
}
}


}else {
$out = $data[$fieldName];
$out = $data;
}

return $this->_confirmValueOutput($out);
Expand Down

0 comments on commit 124b5d9

Please sign in to comment.