Form : Added some translations to the new form system

SVN:trunk[3953]
This commit is contained in:
Guillaume Lajarige
2016-03-16 16:46:58 +00:00
parent 4b7fb20eaf
commit 37e3cb6285
2 changed files with 11 additions and 15 deletions

View File

@@ -20,6 +20,7 @@
namespace Combodo\iTop\Form\Field;
use \Closure;
use \Dict;
use \Combodo\iTop\Form\Field\MultipleChoicesField;
/**
@@ -29,7 +30,7 @@ use \Combodo\iTop\Form\Field\MultipleChoicesField;
*/
class SelectField extends MultipleChoicesField
{
const DEFAULT_NULL_CHOICE_LABEL = 'TOTR: - Choisir une valeur -';
const DEFAULT_NULL_CHOICE_LABEL = 'UI:SelectOne';
const DEFAULT_STARTS_WITH_NULL_CHOICE = true;
protected $bStartsWithNullChoice;
@@ -55,30 +56,23 @@ class SelectField extends MultipleChoicesField
{
$this->bStartsWithNullChoice = $bStartsWithNullChoice;
if (!array_key_exists(null, $this->aChoices))
{
$this->aChoices = array(null => static::DEFAULT_NULL_CHOICE_LABEL) + $this->aChoices;
}
return $this;
}
/**
* Sets the choices for the fields
* Overloads the methods for the super class in order to put a dummy choice first if necessary.
* Returns the field choices with null choice first
*
* @param array $aChoices
* @return \Combodo\iTop\Form\Field\SelectField
* @return array
*/
public function SetChoices($aChoices)
public function GetChoices()
{
$aChoices = parent::GetChoices();
if ($this->bStartsWithNullChoice && !array_key_exists(null, $aChoices))
{
$aChoices = array(null => static::DEFAULT_NULL_CHOICE_LABEL) + $aChoices;
$aChoices = array(null => Dict::S(static::DEFAULT_NULL_CHOICE_LABEL)) + $aChoices;
}
parent::SetChoices($aChoices);
return $this;
return $aChoices;
}
}

View File

@@ -103,7 +103,7 @@ EOF
{
// Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
$sSelectedAtt = ($this->oField->GetCurrentValue() == $sChoice) ? 'selected' : '';
$oOutput->AddHtml('<option value="' . $sChoice . '" ' . $sSelectedAtt . ' >' . $sLabel . '</option>');
$oOutput->AddHtml('<option value="' . $sChoice . '" ' . $sSelectedAtt . ' >')->AddHtml($sLabel, true)->AddHtml('</option>');
}
$oOutput->AddHtml('</select>');
$oOutput->AddHtml('</div>');
@@ -267,6 +267,8 @@ EOF
$("[data-field-id='{$this->oField->GetId()}'][data-form-path='{$this->oField->GetFormPath()}']").portal_form_field_html($sFormFieldOptions);
EOF
);
// MagnificPopup on images
$oOutput->AddJs(InlineImage::FixImagesWidth());
break;
}