LSformElement::getEmptyField() / LSformElement.tpl: Provide value index as $value_idx template variable

This commit is contained in:
Benjamin Renard 2020-09-08 18:42:54 +02:00
parent df1c46eab6
commit 6a3fd60d3e
9 changed files with 93 additions and 52 deletions

View file

@ -667,16 +667,17 @@ class LSform extends LSlog_staticLoggerClass {
} }
/** /**
* Retourne le code HTML d'un champ vide. * Return the HTML code of an empty form field
* *
* @param[in] string Le nom du champ du formulaire * @param[in] $element string The form element name
* @param[in] $value_idx integer|null The value index (optional, default: null == 0)
* *
* @retval string Le code HTML du champ vide. * @retval string|null The HTML code of the specified field if exist, null otherwise
*/ */
public function getEmptyField($element) { public function getEmptyField($element, $value_idx=null) {
$element = $this -> getElement($element); $element = $this -> getElement($element);
if ($element) { if ($element) {
return $element -> getEmptyField(); return $element -> getEmptyField($value_idx);
} }
else { else {
return; return;
@ -777,10 +778,12 @@ class LSform extends LSlog_staticLoggerClass {
$object = new $_REQUEST['objecttype'](); $object = new $_REQUEST['objecttype']();
$object -> loadData($_REQUEST['objectdn']); $object -> loadData($_REQUEST['objectdn']);
$form = $object -> getForm($_REQUEST['idform']); $form = $object -> getForm($_REQUEST['idform']);
$emptyField=$form -> getEmptyField($_REQUEST['attribute']); $value_idx = (isset($_REQUEST['value_idx'])?$_REQUEST['value_idx']:0);
$emptyField = $form -> getEmptyField($_REQUEST['attribute'], $value_idx);
if ( $emptyField ) { if ( $emptyField ) {
$data = array( $data = array(
'html' => $form -> getEmptyField($_REQUEST['attribute']), 'html' => $emptyField,
'value_idx' => $value_idx,
'fieldId' => $_REQUEST['fieldId'], 'fieldId' => $_REQUEST['fieldId'],
'fieldtype' => get_class($form -> getElement($_REQUEST['attribute'])) 'fieldtype' => get_class($form -> getElement($_REQUEST['attribute']))
); );

View file

@ -322,12 +322,20 @@ class LSformElement extends LSlog_staticLoggerClass {
} }
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty form field
* *
* @retval string Code HTML d'un champ vide. * @param[in] $value_idx integer|null The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
*/ */
public function getEmptyField() { public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate($this -> fieldTemplate); return $this -> fetchTemplate(
$this -> fieldTemplate,
array(
'value' => null,
'value_idx' => intval($value_idx),
)
);
} }
/** /**

View file

@ -60,14 +60,21 @@ class LSformElement_labeledValue extends LSformElement {
} }
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty form field
* *
* @retval string Code HTML d'un champ vide. * @param[in] $value_idx integer|null The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
*/ */
public function getEmptyField() { public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate($this -> fieldTemplate,array( return $this -> fetchTemplate(
$this -> fieldTemplate,
array(
'value' => null,
'value_idx' => intval($value_idx),
'labels' => $this -> getParam('html_options.labels'), 'labels' => $this -> getParam('html_options.labels'),
)); )
);
} }
/** /**

View file

@ -95,15 +95,19 @@ class LSformElement_mailQuota extends LSformElement {
} }
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty form field
* *
* @retval string Code HTML d'un champ vide. * @param[in] $value_idx integer|null The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
*/ */
public function getEmptyField() { public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate( return $this -> fetchTemplate(
$this -> fieldTemplate, $this -> fieldTemplate,
array( array(
'sizeFacts' => $this -> sizeFacts 'value' => null,
'value_idx' => intval($value_idx),
'sizeFacts' => $this -> sizeFacts,
) )
); );
} }

View file

@ -95,15 +95,19 @@ class LSformElement_quota extends LSformElement {
} }
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty form field
* *
* @retval string Code HTML d'un champ vide. * @param[in] $value_idx integer|null The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
*/ */
public function getEmptyField() { public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate( return $this -> fetchTemplate(
$this -> fieldTemplate, $this -> fieldTemplate,
array( array(
'sizeFacts' => $this -> sizeFacts 'value' => null,
'value_idx' => intval($value_idx),
'sizeFacts' => $this -> sizeFacts,
) )
); );
} }

View file

@ -119,12 +119,21 @@ class LSformElement_supannCompositeAttribute extends LSformElement {
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty form field
* *
* @retval string Code HTML d'un champ vide. * @param[in] $value_idx integer|null The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
*/ */
public function getEmptyField() { public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate($this -> fieldTemplate,array('components' => $this -> components)); return $this -> fetchTemplate(
$this -> fieldTemplate,
array(
'value' => null,
'value_idx' => intval($value_idx),
'components' => $this -> components,
)
);
} }
/** /**

View file

@ -124,15 +124,19 @@ class LSformElement_valueWithUnit extends LSformElement {
} }
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty form field
* *
* @retval string Code HTML d'un champ vide. * @param[in] $value_idx integer|null The value index (optional, default: null == 0)
*
* @retval string The HTML code of an empty field
*/ */
public function getEmptyField() { public function getEmptyField($value_idx=null) {
return $this -> fetchTemplate( return $this -> fetchTemplate(
$this -> fieldTemplate, $this -> fieldTemplate,
array( array(
'units' => $this -> getUnits() 'value' => null,
'value_idx' => intval($value_idx),
'units' => $this -> getUnits(),
) )
); );
} }

View file

@ -27,7 +27,8 @@ var LSformElement = new Class({
objecttype: this.LSform.objecttype, objecttype: this.LSform.objecttype,
objectdn: this.LSform.objectdn, objectdn: this.LSform.objectdn,
idform: this.LSform.idform, idform: this.LSform.idform,
fieldId: field.id fieldId: field.id,
value_idx: this.ul.getChildren('li').length,
}; };
LSdebug(data); LSdebug(data);
data.imgload = varLSdefault.loadingImgDisplay(field.li,'inside'); data.imgload = varLSdefault.loadingImgDisplay(field.li,'inside');

View file

@ -1,8 +1,9 @@
<ul class='LSform{if $multiple && !$freeze} LSformElement_multiple'{/if}' id='{$attr_name|escape:"quotes"}'> <ul class='LSform{if $multiple && !$freeze} LSformElement_multiple{/if}' id='{$attr_name|escape:"quotes"}'>
{foreach from=$values item=value} {foreach from=$values key=value_idx item=value}
<li>{include file="ls:$fieldTemplate"}</li> <li>{include file="ls:$fieldTemplate"}</li>
{foreachelse} {foreachelse}
{assign var=value value=""} {assign var=value value=""}
{assign var=value_idx value=0}
<li>{include file="ls:$fieldTemplate"}</li> <li>{include file="ls:$fieldTemplate"}</li>
{/foreach} {/foreach}
</ul> </ul>