mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 06:51:42 +00:00
algunos campos solo se escriben una vez, como los precios en la tienda
This commit is contained in:
parent
67f145cb3f
commit
3d3934ac43
3 changed files with 17 additions and 1 deletions
|
@ -78,6 +78,7 @@ module ApplicationHelper
|
|||
{
|
||||
class: "form-control #{invalid(metadata.post, attribute)} #{extra[:class]}",
|
||||
required: required,
|
||||
disabled: metadata.disabled?,
|
||||
autofocus: (metadata.post.attributes.first == attribute),
|
||||
aria: {
|
||||
describedby: id_for_help(attribute),
|
||||
|
|
|
@ -148,6 +148,21 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
|
|||
layout.metadata.dig(name, 'private').present?
|
||||
end
|
||||
|
||||
# Determina si el campo debería estar deshabilitado
|
||||
def disabled?
|
||||
layout.metadata.dig(name, 'disabled') || !writable?
|
||||
end
|
||||
|
||||
# Determina si el campo es de solo lectura
|
||||
#
|
||||
# once => el campo solo se puede modificar si estaba vacío
|
||||
def writable?
|
||||
case layout.metadata.dig(name, 'writable')
|
||||
when 'once' then value.blank?
|
||||
else true
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Si es obligatorio no puede estar vacío
|
||||
|
|
|
@ -379,7 +379,7 @@ class Post
|
|||
# Ejecuta la acción de guardado en cada atributo.
|
||||
def save_attributes!
|
||||
attributes.map do |attr|
|
||||
self[attr].save
|
||||
self[attr].writable? && self[attr].save
|
||||
end.all?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue