avo 1.22.0 → 1.22.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

@@ -59,6 +59,12 @@
59
59
  disabled: disabled
60
60
  }
61
61
  %>
62
+ <%
63
+ # If the select field is disabled, no value will be sent. It's how HTML works.
64
+ # Thus the extra hidden field to actually send the related id to the server.
65
+ if disabled %>
66
+ <%= @form.hidden_field "#{@field.foreign_key}_id" %>
67
+ <% end %>
62
68
  <% end %>
63
69
  <% end %>
64
70
  </div>
@@ -78,6 +84,7 @@
78
84
  <%= @form.select @field.foreign_key, @field.options.map { |o| [o[:label], o[:value]] },
79
85
  {
80
86
  include_blank: @field.placeholder,
87
+ value: @field.value
81
88
  },
82
89
  {
83
90
  class: helpers.input_classes('w-full', has_error: @field.model_errors.include?(@field.id)),
@@ -74,6 +74,13 @@ export default class extends Controller {
74
74
  if (select) {
75
75
  select.setAttribute('valid-name', select.getAttribute('name'))
76
76
  }
77
+ const hiddenInput = target.querySelector('input[type="hidden"]')
78
+ if (hiddenInput) {
79
+ hiddenInput.setAttribute(
80
+ 'valid-name',
81
+ hiddenInput.getAttribute('name'),
82
+ )
83
+ }
77
84
 
78
85
  if (this.selectedType !== type) {
79
86
  select.selectedIndex = 0
@@ -105,7 +112,9 @@ export default class extends Controller {
105
112
  hiddenInput.setAttribute('name', hiddenInput.getAttribute('valid-name'))
106
113
  } else {
107
114
  const select = target.querySelector('select')
115
+ const hiddenInput = target.querySelector('input[type="hidden"]')
108
116
  select.setAttribute('name', select.getAttribute('valid-name'))
117
+ hiddenInput.setAttribute('name', hiddenInput.getAttribute('valid-name'))
109
118
  }
110
119
  }
111
120
 
@@ -122,6 +131,7 @@ export default class extends Controller {
122
131
  } else if (target) {
123
132
  try {
124
133
  target.querySelector('select').setAttribute('name', '')
134
+ target.querySelector('input[type="hidden"]').setAttribute('name', '')
125
135
  } catch (error) {}
126
136
  }
127
137
  }
data/db/factories.rb CHANGED
@@ -17,7 +17,7 @@ FactoryBot.define do
17
17
  end
18
18
 
19
19
  factory :post do
20
- name { Faker::Quote.famous_last_words }
20
+ name { Faker::Quote.unique.famous_last_words }
21
21
  body { Faker::Lorem.paragraphs(number: rand(4...10)).join("\n") }
22
22
  is_featured { [true, false].sample }
23
23
  published_at do
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "1.22.0"
2
+ VERSION = "1.22.1.pre.1"
3
3
  end
@@ -81113,6 +81113,10 @@
81113
81113
  if (select) {
81114
81114
  select.setAttribute("valid-name", select.getAttribute("name"));
81115
81115
  }
81116
+ const hiddenInput = target.querySelector('input[type="hidden"]');
81117
+ if (hiddenInput) {
81118
+ hiddenInput.setAttribute("valid-name", hiddenInput.getAttribute("name"));
81119
+ }
81116
81120
  if (this.selectedType !== type) {
81117
81121
  select.selectedIndex = 0;
81118
81122
  }
@@ -81134,7 +81138,9 @@
81134
81138
  hiddenInput.setAttribute("name", hiddenInput.getAttribute("valid-name"));
81135
81139
  } else {
81136
81140
  const select = target.querySelector("select");
81141
+ const hiddenInput = target.querySelector('input[type="hidden"]');
81137
81142
  select.setAttribute("name", select.getAttribute("valid-name"));
81143
+ hiddenInput.setAttribute("name", hiddenInput.getAttribute("valid-name"));
81138
81144
  }
81139
81145
  }
81140
81146
  invalidateTarget(target) {
@@ -81147,6 +81153,7 @@
81147
81153
  } else if (target) {
81148
81154
  try {
81149
81155
  target.querySelector("select").setAttribute("name", "");
81156
+ target.querySelector('input[type="hidden"]').setAttribute("name", "");
81150
81157
  } catch (error2) {
81151
81158
  }
81152
81159
  }