pxs-forms 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/pxs/forms/model_form_builder.rb +10 -20
 - data/lib/pxs/forms/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: efd3c44a4990b55513ce3a025fa5a3e763667733668cdc3ecbd16859fec1629a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c3274a8654d27e4785b4ae937218dc5c48f12e283038b052ccaaf385df94c91b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f9eb444f40f1f9b869c29a2dfdb64f7206ea546f557296c880a704ce1d2f0d8ed5a3e1e2eef316dfdfafbcedf38735cf9df765d33e98cdf7ceba485ea3693b85
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b529cad7defd4dc231af3a7e77324a54e7fb03c9c7df3ee2bf475f85dc6ec8410ca59d9d81ceb08b1d8d70ca9a942118177e5b8b5a527c111e8a242636fc1d86
         
     | 
| 
         @@ -2,30 +2,22 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
                delegate :tag, :safe_join, to: :@template
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
                # define a model field
         
     | 
| 
       6 
     | 
    
         
            -
                # the format is deduced from the column type or attribute name
         
     | 
| 
       7 
5 
     | 
    
         
             
                def field(attribute, options = {})
         
     | 
| 
       8 
6 
     | 
    
         
             
                    @form_options = options
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                    # extract the object type from the attribute
         
     | 
| 
       11 
7 
     | 
    
         
             
                    object_type = object_type_for_attribute(attribute)
         
     | 
| 
       12 
8 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
                    # set the input type depending on the attribute type
         
     | 
| 
       14 
9 
     | 
    
         
             
                    input_type = case object_type
         
     | 
| 
       15 
10 
     | 
    
         
             
                        when :date then :string
         
     | 
| 
       16 
11 
     | 
    
         
             
                        when :integer then :string
         
     | 
| 
       17 
12 
     | 
    
         
             
                        else object_type
         
     | 
| 
       18 
13 
     | 
    
         
             
                    end
         
     | 
| 
       19 
14 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                    # if as: :input_type is set, use it to set input type
         
     | 
| 
       21 
15 
     | 
    
         
             
                    override_input_type = if options[:as]
         
     | 
| 
       22 
16 
     | 
    
         
             
                        options[:as]
         
     | 
| 
       23 
     | 
    
         
            -
                    # for collections, use a Select
         
     | 
| 
       24 
17 
     | 
    
         
             
                    elsif options[:collection]
         
     | 
| 
       25 
18 
     | 
    
         
             
                        :select
         
     | 
| 
       26 
19 
     | 
    
         
             
                    end
         
     | 
| 
       27 
20 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                    # return result of [input_type]_input method
         
     | 
| 
       29 
21 
     | 
    
         
             
                    send("#{override_input_type || input_type}_input", attribute, options)
         
     | 
| 
       30 
22 
     | 
    
         
             
                end
         
     | 
| 
       31 
23 
     | 
    
         | 
| 
         @@ -57,7 +49,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       57 
49 
     | 
    
         
             
                    field_block(attribute, options) do
         
     | 
| 
       58 
50 
     | 
    
         
             
                        safe_join [
         
     | 
| 
       59 
51 
     | 
    
         
             
                            (field_label(attribute, options[:label]) unless options[:label] == false),
         
     | 
| 
       60 
     | 
    
         
            -
                            string_field(attribute, merge_input_options({class: " 
     | 
| 
      
 52 
     | 
    
         
            +
                            string_field(attribute, merge_input_options({class: "#{"is-invalid" if has_error?(attribute)}"}, options)),
         
     | 
| 
       61 
53 
     | 
    
         
             
                        ]
         
     | 
| 
       62 
54 
     | 
    
         
             
                    end
         
     | 
| 
       63 
55 
     | 
    
         
             
                end
         
     | 
| 
         @@ -66,7 +58,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       66 
58 
     | 
    
         
             
                    field_block(attribute, options) do
         
     | 
| 
       67 
59 
     | 
    
         
             
                        safe_join [
         
     | 
| 
       68 
60 
     | 
    
         
             
                        (field_label(attribute, options[:label]) unless options[:label] == false),
         
     | 
| 
       69 
     | 
    
         
            -
                        text_area(attribute, merge_input_options({class: " 
     | 
| 
      
 61 
     | 
    
         
            +
                        text_area(attribute, merge_input_options({class: "#{"is-invalid" if has_error?(attribute)}"}, options)),
         
     | 
| 
       70 
62 
     | 
    
         
             
                        ]
         
     | 
| 
       71 
63 
     | 
    
         
             
                    end
         
     | 
| 
       72 
64 
     | 
    
         
             
                end
         
     | 
| 
         @@ -75,7 +67,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       75 
67 
     | 
    
         
             
                    field_block(attribute, options) do
         
     | 
| 
       76 
68 
     | 
    
         
             
                        tag.div(class: "checkbox-field") do
         
     | 
| 
       77 
69 
     | 
    
         
             
                        safe_join [
         
     | 
| 
       78 
     | 
    
         
            -
                            check_box(attribute, merge_input_options({class: "checkbox-input"}, options 
     | 
| 
      
 70 
     | 
    
         
            +
                            check_box(attribute, merge_input_options({class: "checkbox-input"}, options)),
         
     | 
| 
       79 
71 
     | 
    
         
             
                            label(attribute, options[:label], class: "checkbox-label"),
         
     | 
| 
       80 
72 
     | 
    
         
             
                        ]
         
     | 
| 
       81 
73 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -93,16 +85,14 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       93 
85 
     | 
    
         | 
| 
       94 
86 
     | 
    
         
             
                def select_input(attribute, options = {})
         
     | 
| 
       95 
87 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
                     
     | 
| 
       97 
     | 
    
         
            -
                     
     | 
| 
       98 
     | 
    
         
            -
                     
     | 
| 
       99 
     | 
    
         
            -
                    text_method = options[:text_method] || :name
         
     | 
| 
       100 
     | 
    
         
            -
                    input_options = options[:input_html] || {}
         
     | 
| 
      
 88 
     | 
    
         
            +
                    value_method = options[:value_method] || :to_s
         
     | 
| 
      
 89 
     | 
    
         
            +
                    text_method = options[:text_method] || :to_s
         
     | 
| 
      
 90 
     | 
    
         
            +
                    input_options = options || {}
         
     | 
| 
       101 
91 
     | 
    
         | 
| 
       102 
92 
     | 
    
         
             
                    multiple = input_options[:multiple]
         
     | 
| 
       103 
93 
     | 
    
         | 
| 
       104 
94 
     | 
    
         
             
                    collection_input(attribute, options) do
         
     | 
| 
       105 
     | 
    
         
            -
                        collection_select(attribute, options[:collection], value_method, text_method, options, merge_input_options({class: "#{"custom-select" unless multiple}  
     | 
| 
      
 95 
     | 
    
         
            +
                        collection_select(attribute, options[:collection], value_method, text_method, options, merge_input_options({class: "#{"custom-select" unless multiple} #{"is-invalid" if has_error?(attribute)}"}, options))
         
     | 
| 
       106 
96 
     | 
    
         
             
                    end
         
     | 
| 
       107 
97 
     | 
    
         
             
                end
         
     | 
| 
       108 
98 
     | 
    
         | 
| 
         @@ -110,7 +100,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       110 
100 
     | 
    
         | 
| 
       111 
101 
     | 
    
         
             
                    # We probably need to go back later and adjust this for more customization
         
     | 
| 
       112 
102 
     | 
    
         
             
                    collection_input(attribute, options) do
         
     | 
| 
       113 
     | 
    
         
            -
                    grouped_collection_select(attribute, options[:collection], :last, :first, :to_s, :to_s, options, merge_input_options({class: "custom-select  
     | 
| 
      
 103 
     | 
    
         
            +
                    grouped_collection_select(attribute, options[:collection], :last, :first, :to_s, :to_s, options, merge_input_options({class: "custom-select #{"is-invalid" if has_error?(attribute)}"}, options))
         
     | 
| 
       114 
104 
     | 
    
         
             
                  end
         
     | 
| 
       115 
105 
     | 
    
         
             
                end
         
     | 
| 
       116 
106 
     | 
    
         | 
| 
         @@ -176,7 +166,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       176 
166 
     | 
    
         
             
                end
         
     | 
| 
       177 
167 
     | 
    
         | 
| 
       178 
168 
     | 
    
         
             
                def field_block(attribute, options = {}, &block)
         
     | 
| 
       179 
     | 
    
         
            -
                    tag.div class: "field #{attribute}" 
     | 
| 
      
 169 
     | 
    
         
            +
                    tag.div class: "field #{attribute}" do
         
     | 
| 
       180 
170 
     | 
    
         
             
                        safe_join [
         
     | 
| 
       181 
171 
     | 
    
         
             
                            block.call,
         
     | 
| 
       182 
172 
     | 
    
         
             
                            hint_text(options[:hint]),
         
     | 
| 
         @@ -197,7 +187,7 @@ class ModelFormBuilder < ActionView::Helpers::FormBuilder 
     | 
|
| 
       197 
187 
     | 
    
         | 
| 
       198 
188 
     | 
    
         
             
                def error_text(attribute)
         
     | 
| 
       199 
189 
     | 
    
         
             
                    if has_error? attribute
         
     | 
| 
       200 
     | 
    
         
            -
                        tag.div @object.errors[ 
     | 
| 
      
 190 
     | 
    
         
            +
                        tag.div @object.errors[method].join("<br />").html_safe, class: "form-errors"
         
     | 
| 
       201 
191 
     | 
    
         
             
                    end
         
     | 
| 
       202 
192 
     | 
    
         
             
                end
         
     | 
| 
       203 
193 
     | 
    
         | 
    
        data/lib/pxs/forms/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: pxs-forms
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.10
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Poubelle
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-04-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     |