Автоматическая установка значений по умолчанию — различия между версиями
VITL' (обсуждение | вклад)  | 
				VITL' (обсуждение | вклад)   | 
				||
| Строка 11: | Строка 11: | ||
<pre>  | <pre>  | ||
<xsl:template match="field[@type = 'string' or @type = 'int' or @type = 'price' or @type = 'float' or @type = 'counter']"    | <xsl:template match="field[@type = 'string' or @type = 'int' or @type = 'price' or @type = 'float' or @type = 'counter']"    | ||
| − | mode="form-modify">  | + |   mode="form-modify">  | 
...  | ...  | ||
</xsl:template>  | </xsl:template>  | ||
| Строка 22: | Строка 22: | ||
   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umi="http://www.umi-cms.ru/TR/umi">  |    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umi="http://www.umi-cms.ru/TR/umi">  | ||
     <xsl:template match="field[@type = 'string' or @type = 'int' or @type = 'price' or @type = 'float' or @type = 'counter']"    |      <xsl:template match="field[@type = 'string' or @type = 'int' or @type = 'price' or @type = 'float' or @type = 'counter']"    | ||
| − | + |       mode="form-modify">  | |
       <div class="field">  |        <div class="field">  | ||
         <label for="{generate-id()}">  |          <label for="{generate-id()}">  | ||
| Строка 57: | Строка 57: | ||
<pre>  | <pre>  | ||
<xsl:template match="field[@type = 'boolean']" mode="form-modify">  | <xsl:template match="field[@type = 'boolean']" mode="form-modify">  | ||
| + | ...  | ||
</xsl:template>  | </xsl:template>  | ||
</pre>  | </pre>  | ||
В зависимости от того к какому модулю относятся те или иные страницы, шаблон form.modify.custom.xsl создается в соответствующей папке, с тем же названием, что и модуль.  | В зависимости от того к какому модулю относятся те или иные страницы, шаблон form.modify.custom.xsl создается в соответствующей папке, с тем же названием, что и модуль.  | ||
Версия 12:38, 26 сентября 2010
Если необходимо, чтобы для поля типа "Дата" автоматически устанавливалось текущее время, при добавлении страницы, то необходимо установить идентификатор для вашего поля равным publish_time. Данное действие будет происходить благодаря шаблону:
<xsl:template match="field[@type = 'date']" mode="form-modify"> ... </xsl:template>
в файле \styles\skins\mac\data\form.modify.xsl
Если необходимо, чтобы при создании объекта каталога, для некоторых полей автоматически устанавливались значения по умолчанию, допустим для поля "Вес" или "Максимальная скорость", тогда необходимо в папке \styles\skins\mac\data\modules\catalog\ создать файл form.modify.custom.xsl и скопировать в него необходимый шаблон из \styles\skins\mac\data\form.modify.xsl. Если мы рассматриваем значения полей типа Строка, число, цена и т.п., то необходимо скопировать шаблон:
<xsl:template match="field[@type = 'string' or @type = 'int' or @type = 'price' or @type = 'float' or @type = 'counter']" mode="form-modify"> ... </xsl:template>
в итоге, файл styles\skins\mac\data\modules\catalog\form.modify.custom.xsl будет примерно следующего вида:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet SYSTEM "ulang://common">
  <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:umi="http://www.umi-cms.ru/TR/umi">
    <xsl:template match="field[@type = 'string' or @type = 'int' or @type = 'price' or @type = 'float' or @type = 'counter']" 
      mode="form-modify">
      <div class="field">
        <label for="{generate-id()}">
          <span class="label">
            <acronym>
              <xsl:apply-templates select="." mode="sys-tips" />
              <xsl:value-of select="@title" />
            </acronym>
            <xsl:apply-templates select="." mode="required_text" />
          </span>
          <span>
            <input type="text" name="{@input_name}" id="{generate-id()}">
              <xsl:apply-templates select="." mode="required_attr">
                <xsl:with-param name="old_class" select="@type" />
              </xsl:apply-templates>
              <xsl:attribute name="value">
                <xsl:choose>
                  <xsl:when test="@name='weight' and string-length(text())=0">100</xsl:when>
                  <xsl:when test="@name='max' and string-length(text())=0">135</xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="." />
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
            </input>
          </span>
        </label>
      </div>
    </xsl:template>
  </xsl:stylesheet>
для полей с идентификаторами 'weight' и 'max' мы установили значения по умолчанию равными 100 и 135. Аналогичным образом осуществляется настройка и других полей. Для других типов полей, допустим boolean, необходимо переназначать уже другой шаблон:
<xsl:template match="field[@type = 'boolean']" mode="form-modify"> ... </xsl:template>
В зависимости от того к какому модулю относятся те или иные страницы, шаблон form.modify.custom.xsl создается в соответствующей папке, с тем же названием, что и модуль.