@@ -77,9 +77,7 @@ defmodule Backpex.FormComponent do
77
77
end
78
78
79
79
def handle_event ( "validate" , % { "change" => change , "_target" => target } , % { assigns: % { action_type: :item } } = socket ) do
80
- % { assigns: % { item: item , live_resource: live_resource , live_action: live_action } = assigns } = socket
81
- fields = live_resource . fields ( live_action , assigns )
82
-
80
+ % { assigns: % { item: item , fields: fields } = assigns } = socket
83
81
changeset_function = & assigns . action_to_confirm . module . changeset / 3
84
82
85
83
target = Enum . at ( target , 1 )
@@ -107,17 +105,11 @@ defmodule Backpex.FormComponent do
107
105
end
108
106
109
107
def handle_event ( "validate" , % { "change" => change , "_target" => target } , socket ) do
110
- % {
111
- live_resource: live_resource ,
112
- live_action: live_action ,
113
- item: item
114
- } = socket . assigns
108
+ % { live_resource: live_resource , fields: fields , item: item } = socket . assigns
115
109
116
110
target = Enum . at ( target , 1 )
117
111
assocs = Map . get ( socket . assigns , :assocs , [ ] )
118
112
119
- fields = live_resource . fields ( live_action , socket . assigns )
120
-
121
113
change =
122
114
change
123
115
|> drop_readonly_changes ( fields , socket . assigns )
@@ -151,11 +143,9 @@ defmodule Backpex.FormComponent do
151
143
152
144
def handle_event ( "cancel-existing-entry" , % { "ref" => file_key , "id" => upload_key } , socket ) do
153
145
upload_key = String . to_existing_atom ( upload_key )
154
- % { live_resource: live_resource , live_action: live_action } = socket . assigns
155
- fields = live_resource . fields ( live_action , socket . assigns )
156
146
157
147
field =
158
- fields
148
+ socket . assigns . fields
159
149
|> Enum . find ( fn { _name , field_options } ->
160
150
Map . has_key? ( field_options , :upload_key ) and Map . get ( field_options , :upload_key ) == upload_key
161
151
end )
@@ -181,8 +171,7 @@ defmodule Backpex.FormComponent do
181
171
end
182
172
183
173
def handle_event ( "save" , % { "change" => change , "save-type" => save_type } , socket ) do
184
- % { assigns: % { live_resource: live_resource , live_action: live_action } = assigns } = socket
185
- fields = live_resource . fields ( live_action , assigns )
174
+ % { assigns: % { live_action: live_action , fields: fields } = assigns } = socket
186
175
187
176
change =
188
177
change
@@ -205,10 +194,7 @@ defmodule Backpex.FormComponent do
205
194
end
206
195
207
196
def handle_event ( msg , params , socket ) do
208
- % { live_resource: live_resource , live_action: live_action } = socket . assigns
209
- fields = live_resource . fields ( live_action , socket . assigns )
210
-
211
- Enum . reduce ( fields , socket , fn el , acc ->
197
+ Enum . reduce ( socket . assigns . fields , socket , fn el , acc ->
212
198
el . module . handle_form_event ( el , msg , params , acc )
213
199
end )
214
200
|> noreply ( )
@@ -309,15 +295,14 @@ defmodule Backpex.FormComponent do
309
295
assigns:
310
296
% {
311
297
live_resource: live_resource ,
312
- live_action: live_action ,
298
+ fields: fields ,
313
299
resource_action: resource_action ,
314
300
item: item ,
315
301
return_to: return_to
316
302
} = assigns
317
303
} = socket
318
304
319
305
assocs = Map . get ( assigns , :assocs , [ ] )
320
- fields = live_resource . fields ( live_action , assigns )
321
306
params = drop_readonly_changes ( params , fields , assigns )
322
307
323
308
result =
@@ -361,14 +346,13 @@ defmodule Backpex.FormComponent do
361
346
assigns:
362
347
% {
363
348
live_resource: live_resource ,
364
- live_action: live_action ,
349
+ fields: fields ,
365
350
selected_items: selected_items ,
366
351
action_to_confirm: action_to_confirm ,
367
352
return_to: return_to
368
353
} = assigns
369
354
} = socket
370
355
371
- fields = live_resource . fields ( live_action , assigns )
372
356
params = drop_readonly_changes ( params , fields , assigns )
373
357
374
358
result =
0 commit comments