mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 06:36:21 +00:00
los campos multiples pueden ser cerrados
tuvimos que volver a select2 4.0.5 porque hay un bug que impide procesar los data-*
This commit is contained in:
parent
017ece020c
commit
3aa9af3fb5
7 changed files with 37 additions and 5 deletions
|
@ -83,6 +83,27 @@ class Post
|
||||||
array?
|
array?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Detecta si el valor es una tabla de campos
|
||||||
|
def nested?
|
||||||
|
value.is_a? Hash
|
||||||
|
end
|
||||||
|
|
||||||
|
# Un campo acepta valores abiertos si no es un array con múltiples
|
||||||
|
# elementos
|
||||||
|
def open?
|
||||||
|
# Todos los valores simples son abiertos
|
||||||
|
return true unless complex?
|
||||||
|
return false unless array?
|
||||||
|
# La cosa se complejiza cuando tenemos valores complejos
|
||||||
|
#
|
||||||
|
# Si tenemos una lista cerrada de valores, necesitamos saber si el
|
||||||
|
# campo es abierto o cerrado. Si la lista tiene varios elementos,
|
||||||
|
# es una lista cerrada, opcionalmente abierta. Si la lista tiene
|
||||||
|
# un elemento, quiere decir que estamos autocompletando desde otro
|
||||||
|
# lado.
|
||||||
|
contents.fetch('open', value.count < 2)
|
||||||
|
end
|
||||||
|
|
||||||
# Obtiene los valores posibles para el campo de la plantilla
|
# Obtiene los valores posibles para el campo de la plantilla
|
||||||
def values
|
def values
|
||||||
return '' if %w[string text].include? value
|
return '' if %w[string text].include? value
|
||||||
|
|
|
@ -95,7 +95,11 @@
|
||||||
- when 'select'
|
- when 'select'
|
||||||
= select_tag name, options_for_select(template.values, @post.get_front_matter(template)),
|
= select_tag name, options_for_select(template.values, @post.get_front_matter(template)),
|
||||||
{ class: 'form-control select2',
|
{ class: 'form-control select2',
|
||||||
multiple: template.multiple? }
|
multiple: template.multiple?,
|
||||||
|
data: { tags: template.open?,
|
||||||
|
placeholder: t('posts.select.placeholder')}}
|
||||||
|
- if template.open?
|
||||||
|
%small.text-muted.form-text= t('posts.open')
|
||||||
.invalid-feedback= t('posts.invalid')
|
.invalid-feedback= t('posts.invalid')
|
||||||
.form-group
|
.form-group
|
||||||
= submit_tag t('posts.save'), class: 'btn btn-success', id: 'submit-post'
|
= submit_tag t('posts.save'), class: 'btn btn-success', id: 'submit-post'
|
||||||
|
|
|
@ -203,3 +203,6 @@ en:
|
||||||
title: 'Post needs a title'
|
title: 'Post needs a title'
|
||||||
date: 'Post needs a valid date'
|
date: 'Post needs a valid date'
|
||||||
invalid: 'This field is required!'
|
invalid: 'This field is required!'
|
||||||
|
open: 'Tip: You can add new options by typing them'
|
||||||
|
select:
|
||||||
|
placeholder: 'Type to filter available options'
|
||||||
|
|
|
@ -199,3 +199,6 @@ es:
|
||||||
title: 'Necesita un título'
|
title: 'Necesita un título'
|
||||||
date: 'Necesita una fecha'
|
date: 'Necesita una fecha'
|
||||||
invalid: '¡Este campo es obligatorio!'
|
invalid: '¡Este campo es obligatorio!'
|
||||||
|
open: 'Nota: Puedes agregar más opciones a medida que las escribes'
|
||||||
|
select:
|
||||||
|
placeholder: 'Empieza a escribir para filtrar las opciones disponibles'
|
||||||
|
|
|
@ -207,4 +207,5 @@ required: false
|
||||||
min: nil
|
min: nil
|
||||||
max: nil
|
max: nil
|
||||||
multiple: true
|
multiple: true
|
||||||
|
open: true
|
||||||
```
|
```
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"markdown-it": "^8.4.0",
|
"markdown-it": "^8.4.0",
|
||||||
"marked": "^0.3.12",
|
"marked": "^0.3.12",
|
||||||
"popper.js": "^1.12.9",
|
"popper.js": "^1.12.9",
|
||||||
"select2": "^4.0.6-rc.1",
|
"select2": "4.0.5",
|
||||||
"select2-bootstrap-theme": "https://github.com/angel-vladov/select2-bootstrap-theme",
|
"select2-bootstrap-theme": "https://github.com/angel-vladov/select2-bootstrap-theme",
|
||||||
"table-dragger": "^1.0.2"
|
"table-dragger": "^1.0.2"
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,9 +137,9 @@ rx@^4.1.0:
|
||||||
version "0.1.0-beta.10"
|
version "0.1.0-beta.10"
|
||||||
resolved "https://github.com/angel-vladov/select2-bootstrap-theme#4fb604838e79150161fc636dbeb3b3022c034cda"
|
resolved "https://github.com/angel-vladov/select2-bootstrap-theme#4fb604838e79150161fc636dbeb3b3022c034cda"
|
||||||
|
|
||||||
select2@^4.0.6-rc.1:
|
select2@4.0.5:
|
||||||
version "4.0.6-rc.1"
|
version "4.0.5"
|
||||||
resolved "https://registry.yarnpkg.com/select2/-/select2-4.0.6-rc.1.tgz#aa6c3038a7f0f2e91ffade38f0a21c15e1813276"
|
resolved "https://registry.yarnpkg.com/select2/-/select2-4.0.5.tgz#7aac50692561985b34d3b82ec55e226f8960d40a"
|
||||||
dependencies:
|
dependencies:
|
||||||
almond "~0.3.1"
|
almond "~0.3.1"
|
||||||
jquery-mousewheel "~3.1.13"
|
jquery-mousewheel "~3.1.13"
|
||||||
|
|
Loading…
Reference in a new issue