3.4.2. Маска ввода в редакторе#

3.4.2.1. Общая информация#

Сервер предоставляет возможность использовать маску ввода в редакторах.

Маска ввода реализована при помощи сторонней Javascript библиотеки Imask.

Warning

Если функциональность масок ввода перестанет соответствовать требованиям разработки, рекомендуется выполнить следующие шаги:

  1. Изучить возможности библиотеки Imask на предмет наличия необходимого функционала.

  2. Если требуемые возможности поддерживаются, запросить у системных разработчиков их интеграцию.

  3. Если необходимый функционал отсутствует, рассмотреть альтернативные варианты:
    • Пересмотр и доработка прикладного кода.

    • Замена библиотеки на более подходящую (совместно с системным отделом).

    • Разработка собственного решения (совместно с системным отделом).

3.4.2.2. Виды масок ввода#

Ниже представлена таблица, в которой указаны виды масок ввода, которые можно использовать в редакторах.

Перейдя в метаданные Postgres вы можете детально изучить возможности каждой маски ввода.

Вид маски ввода

Элемент в метаданных Postgres

Маска ввода, которая состоит из паттерна

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern

Маска ввода на основе регулярного выражения

View.Representation.Attributes.Attribute.Editor.EditMask.Regular

Маска ввода для работы с числовыми значениями

View.Representation.Attributes.Attribute.Editor.EditMask.Number

Динамическая маска ввода

View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic

3.4.2.3. Способы установки маски ввода в редактор#

Маски ввода устанавливаются только внутри прикладных приложений.

Маски ввода устанавливаются при помощи элемента editMask в следующих редакторах:

Ниже приведены основные способы, с помощью которых можно установить маску ввода в редактор.

3.4.2.3.1. Через разметку выборки#

Подход, при котором маска ввода устанавливается в *.avm.xml файлах, является основным.

Ниже представлен пример установки маски ввода для редактора в строке.

Установка маски ввода для редактора через разметку выборки#
 1<attr name="edit_mask_1" caption="EditMask#1">
 2    <editor>
 3        <edit>
 4            <editMask> <!--Элемент, с помощью которого производится установка маски ввода в редактор-->
 5                <pattern>
 6                    <items>
 7                        <definition name="0"/>
 8                        <definition name="0"/>
 9                        <definition name="0"/>
10                    </items>
11                </pattern>
12            </editMask>
13        </edit>
14    </editor>
15</attr>

3.4.2.3.2. Через код интерактивной бизнес логики#

Подход, при котором маска ввода устанавливается в *Avi.scala файлах, следует использовать в тех случаях, когда необходимо программно установить маску ввода в редактор.

Это может потребоваться, когда в зависимости от определённых условий в прикладном коде необходимо изменять маску ввода.

Ниже представлен пример установки маски ввода для редактора, который указан в примере для установки маски ввода через разметку выборки.

Установка маски ввода для редактора через код интерактивной бизнес логики#
 1attrs("edit_mask_1").editMask =
 2"""
 3  |{
 4  |  "options": {
 5  |    "type": "PATTERN",
 6  |    "items": [
 7  |    {
 8  |      "type": "DEFINITION",
 9  |      "name": "0"
10  |    },
11  |    {
12  |      "type": "DEFINITION",
13  |      "name": "0"
14  |    },
15  |    {
16  |      "type": "DEFINITION",
17  |      "name": "0"
18  |    }
19  |    ]
20  |  }
21  |}
22  |""".stripMargin

3.4.2.4. Зарезервированные определения#

Ниже представлена таблица, в которой указаны зарезервированные определения, которые можно использовать в View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Definition.key.

Ключ зарезервированного определения

Описание

Регулярное выражение

L

Любая буква

/^\p{L}$/u

A

Любая буква или цифра

/^(\p{L}|[0-9])$/u

C

Любой символ

/^.$/

0

Любая цифра

/^[0-9]$/

#

Любая цифра, символ +, символ -

/^[0-9+-]$/

3.4.2.5. Эквиваленты элементов маски ввода в JSON формате#

В данном разделе описаны JSON-эквиваленты элементов маски ввода. Это поможет понять, как настраивается маска ввода в коде интерактивной бизнес-логики.

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

saveWithLiteralsEnabled

Тип: boolean

View.Representation.Attributes.Attribute.Editor.EditMask.saveWithLiteralsEnabled

Да

options

См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern

Нет

{
    "saveWithLiteralsEnabled": true,
    "options": {} // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

type

Значение: PATTERN

Нет

items

См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items

Нет

definitions

См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Definitions

Да

blocks

См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Blocks

Да

placeholderChar

Тип: string

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.placeholderChar

Да

textTransform

Допустимые значения смотри в View.Representation.Attributes.Attribute.Editor.EditMask.Enums.TextTransformTypes

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.textTransform

Да

eagerEnabled

Тип: boolean

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.eagerEnabled

Да

lazyEnabled

Тип: boolean

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.lazyEnabled

Да

{
  "key": "PATTERN",
  "items": [], //См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items
  "definitions": {}, //См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items
  "blocks": {}, //См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items
  "placeholderChar": "*",
  "textTransform": "DEFAULT",
  "eagerEnabled": false,
  "lazyEnabled": false
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items:

  1. См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Block

  2. См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Definition

  3. См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Literal

[
  // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Block
  // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Definition
  // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Literal
]

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Block:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

type

Значение: BLOCK

Нет

key

Тип: string

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Block.key

Нет

optionalEnabled

Тип: boolean

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Block.optionalEnabled

Да

{
  "type": "BLOCK",
  "key": "test_block_1",
  "optionalEnabled": false
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Definition:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

type

Значение: DEFINITION

Нет

key

Тип: string

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Definition.key

Нет

optionalEnabled

Тип: boolean

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Definition.optionalEnabled

Да

{
  "type": "DEFINITION",
  "key": "a",
  "optionalEnabled": false
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Literal:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

type

Значение: LITERAL

Нет

value

Тип: string

View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Literal.value

Нет

{
  "type": "LITERAL",
  "value": "-"
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Definitions:

Ключ

Значение

Может быть не указано или указано как null

Ключ определения (см. View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Definitions.Definition.key)

См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp

Да

{
  "a": {}, // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp
  "b": {}, // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp
  "c": {}, // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Blocks:

Ключ

Значение

Может быть не указано или указано как null

Ключ блока (см. View.Representation.Attributes.Attribute.Editor.EditMask.Pattern.Items.Block.key)

См. JSON-эквиваленты следующих элементов: View.Representation.Attributes.Attribute.Editor.EditMask.Pattern, View.Representation.Attributes.Attribute.Editor.EditMask.Number, View.Representation.Attributes.Attribute.Editor.EditMask.Regular, View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic

Да

{
  "a": {}, // См. JSON-эквиваленты следующих элементов: View.Representation.Attributes.Attribute.Editor.EditMask.Pattern, View.Representation.Attributes.Attribute.Editor.EditMask.Number, View.Representation.Attributes.Attribute.Editor.EditMask.Regular, View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic
  "block_1": {}, // См. JSON-эквиваленты следующих элементов: View.Representation.Attributes.Attribute.Editor.EditMask.Pattern, View.Representation.Attributes.Attribute.Editor.EditMask.Number, View.Representation.Attributes.Attribute.Editor.EditMask.Regular, View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic
  "test_block_b": {} // См. JSON-эквиваленты следующих элементов: View.Representation.Attributes.Attribute.Editor.EditMask.Pattern, View.Representation.Attributes.Attribute.Editor.EditMask.Number, View.Representation.Attributes.Attribute.Editor.EditMask.Regular, View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Regular:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

type

Значение: REGULAR

Нет

value

См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp

Нет

textTransform

Допустимые значения смотри в View.Representation.Attributes.Attribute.Editor.EditMask.Enums.TextTransformTypes

View.Representation.Attributes.Attribute.Editor.EditMask.Regular.textTransform

Да

{
  "type": "REGULAR",
  "value": {}, // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp
  "textTransform": "DEFAULT"
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.RegExp:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

value

Тип: string

View.Representation.Attributes.Attribute.Editor.EditMask.RegExp.value

Нет

flags

Тип: string

View.Representation.Attributes.Attribute.Editor.EditMask.RegExp.flags

Да

{
  "value": "^[0-9]$",
  "flags": "g"
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Number:

Ключ

Значение

Метаданные Postgres

Может быть не указано или указано как null

type

Значение: NUMBER

Нет

min

Тип: integer

View.Representation.Attributes.Attribute.Editor.EditMask.Number.min

Да

max

Тип: integer

View.Representation.Attributes.Attribute.Editor.EditMask.Number.max

Да

scale

Тип: integer

View.Representation.Attributes.Attribute.Editor.EditMask.Number.scale

Да

thousandsSeparatorEnabled

Тип: boolean

View.Representation.Attributes.Attribute.Editor.EditMask.Number.thousandsSeparatorEnabled

Да

{
  "type": "NUMBER",
  "min": 0,
  "max": 0,
  "scale": 0,
  "thousandsSeparatorEnabled": false,
}

JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic:

Ключ

Значение

Может быть не указано или указано как null

type

Значение: DYNAMIC

Нет

optionsList

Тип: JSON-массив. Массив может содержать следующие JSON-эквиваленты: View.Representation.Attributes.Attribute.Editor.EditMask.Pattern, View.Representation.Attributes.Attribute.Editor.EditMask.Number, View.Representation.Attributes.Attribute.Editor.EditMask.Regular, View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic

Нет

{
  "key": "DYNAMIC",
  "optionsList": [
    // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Pattern
    // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Number
    // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Regular
    // См. JSON-эквивалент View.Representation.Attributes.Attribute.Editor.EditMask.Dynamic
  ]
}

3.4.2.5.1. Примеры масок ввода в JSON формате#

Чтобы лучше разобраться в структуре масок ввода в формате JSON, ниже приведены несколько примеров таких масок. Для удобства указаны все опциональные свойства.

Номер телефона, который начинается с “+7” или “8”
{
  "options": {
    "eagerEnabled": false,
    "blocks": {
      "a": {
        "optionsList": [
          {
            "eagerEnabled": false,
            "blocks": {},
            "placeholderChar": "*",
            "type": "pattern",
            "items": [
              {
                "type": "literal",
                "value": "+"
              },
              {
                "optionalEnabled": false,
                "name": "a",
                "type": "definition"
              }
            ],
            "definitions": {
              "a": {
                "flags": "",
                "value": "^7$"
              }
            },
            "lazyEnabled": false,
            "textTransform": "default"
          },
          {
            "eagerEnabled": false,
            "blocks": {},
            "placeholderChar": "*",
            "type": "pattern",
            "items": [
              {
                "optionalEnabled": false,
                "name": "a",
                "type": "definition"
              }
            ],
            "definitions": {
              "a": {
                "flags": "",
                "value": "^8$"
              }
            },
            "lazyEnabled": false,
            "textTransform": "default"
          }
        ],
        "type": "dynamic"
      }
    },
    "placeholderChar": "*",
    "type": "pattern",
    "items": [
      {
        "optionalEnabled": false,
        "name": "a",
        "type": "block"
      },
      {
        "type": "literal",
        "value": " "
      },
      {
        "type": "literal",
        "value": "("
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "type": "literal",
        "value": ")"
      },
      {
        "type": "literal",
        "value": " "
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "type": "literal",
        "value": "-"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "type": "literal",
        "value": "-"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      },
      {
        "optionalEnabled": false,
        "name": "0",
        "type": "definition"
      }
    ],
    "definitions": {},
    "lazyEnabled": false,
    "textTransform": "default"
  },
  "saveWithLiteralsEnabled": false
}
IPv4-адрес
{
  "options": {
    "eagerEnabled": false,
    "blocks": {
      "a": {
        "min": 0,
        "max": 255,
        "scale": 0,
        "type": "number",
        "thousandsSeparatorEnabled": false
      }
    },
    "placeholderChar": "*",
    "type": "pattern",
    "items": [
      {
        "optionalEnabled": false,
        "name": "a",
        "type": "block"
      },
      {
        "type": "literal",
        "value": "."
      },
      {
        "optionalEnabled": false,
        "name": "a",
        "type": "block"
      },
      {
        "type": "literal",
        "value": "."
      },
      {
        "optionalEnabled": false,
        "name": "a",
        "type": "block"
      },
      {
        "type": "literal",
        "value": "."
      },
      {
        "optionalEnabled": false,
        "name": "a",
        "type": "block"
      }
    ],
    "definitions": {},
    "lazyEnabled": false,
    "textTransform": "default"
  },
  "saveWithLiteralsEnabled": false
}
Любое кол-во цифр, либо ничего
{
  "options": {
    "type": "regular",
    "value": {
      "flags": "",
      "value": "^[0-9]{0,}$"
    },
    "textTransform": "default"
  },
  "saveWithLiteralsEnabled": true
}