alchemy-form 0.3.0-alpha.1 → 0.3.0-alpha.3
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.
- package/CHANGELOG.md +27 -0
- package/assets/stylesheets/form/alchemy_form.scss +1 -2
- package/assets/stylesheets/form/elements/_button.scss +4 -31
- package/assets/stylesheets/form/elements/_dropdown.scss +93 -0
- package/assets/stylesheets/form/elements/_enum_badge.scss +7 -0
- package/assets/stylesheets/form/elements/_feedback_input.scss +2 -0
- package/assets/stylesheets/form/elements/_field.scss +16 -25
- package/assets/stylesheets/form/elements/_form.scss +7 -2
- package/assets/stylesheets/form/elements/_select.scss +176 -176
- package/assets/stylesheets/form/elements/_table.scss +117 -46
- package/assets/stylesheets/form/elements/_tabs.scss +25 -35
- package/assets/stylesheets/form/elements/index.scss +20 -18
- package/assets/stylesheets/form/general/index.scss +2 -2
- package/config/routes.js +10 -0
- package/controller/form_api_controller.js +28 -0
- package/element/00_form_base.js +82 -27
- package/element/10_dataprovider.js +2 -2
- package/element/al_button.js +12 -1
- package/element/al_dropdown.js +123 -0
- package/element/al_dropdown_item.js +40 -0
- package/element/al_enum_badge.js +157 -0
- package/element/al_field.js +196 -37
- package/element/al_field_array.js +22 -0
- package/element/al_field_schema.js +222 -55
- package/element/al_form.js +9 -6
- package/element/al_select.js +2 -2
- package/element/al_table.js +8 -2
- package/helper/field_recompute_handler.js +0 -2
- package/package.json +3 -2
- package/view/form/elements/al_dropdown.hwk +21 -0
- package/view/form/elements/al_enum_badge.hwk +9 -0
- package/view/form/elements/alchemy_field.hwk +3 -12
- package/view/form/elements/alchemy_field_array.hwk +16 -6
- package/view/form/elements/alchemy_field_array_entry.hwk +10 -5
- package/view/form/elements/alchemy_field_schema.hwk +2 -2
- package/view/form/inputs/edit/enum.hwk +1 -1
- package/view/form/inputs/edit_sw/fallback.hwk +1 -0
- package/view/form/inputs/view/association_alias.hwk +16 -0
- package/view/form/inputs/view/schema.hwk +4 -0
- package/view/form/inputs/view/string.hwk +1 -1
- package/view/form/inputs/view_inline/belongs_to.hwk +16 -0
- package/view/form/inputs/view_inline/boolean.hwk +24 -17
- package/view/form/inputs/view_inline/datetime.hwk +31 -24
- package/view/form/inputs/view_inline/enum.hwk +32 -1
- package/view/form/inputs/view_inline/objectid.hwk +9 -1
- package/view/form/inputs/view_inline/string.hwk +11 -3
- package/view/form/wrappers/edit_sw/default.hwk +1 -0
package/element/al_field.js
CHANGED
|
@@ -72,6 +72,24 @@ Field.setAttribute('field-view');
|
|
|
72
72
|
*/
|
|
73
73
|
Field.setAttribute('wrapper-view');
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Minimum amount of values (in case of an array)
|
|
77
|
+
*
|
|
78
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
79
|
+
* @since 0.1.12
|
|
80
|
+
* @version 0.1.12
|
|
81
|
+
*/
|
|
82
|
+
Field.setAttribute('min-entry-count', {type: 'number'});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Maximum amount of values (in case of an array)
|
|
86
|
+
*
|
|
87
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
88
|
+
* @since 0.1.12
|
|
89
|
+
* @version 0.1.12
|
|
90
|
+
*/
|
|
91
|
+
Field.setAttribute('max-entry-count', {type: 'number'});
|
|
92
|
+
|
|
75
93
|
/**
|
|
76
94
|
* Is this a read only field?
|
|
77
95
|
*
|
|
@@ -176,7 +194,7 @@ Field.enforceProperty(function config(new_value, old_value) {
|
|
|
176
194
|
|
|
177
195
|
// If an explicit field is set without a schema,
|
|
178
196
|
// we need to remember it for serializing purposes
|
|
179
|
-
if (new_value && !new_value.schema) {
|
|
197
|
+
if (new_value && (!new_value.schema || new_value == new_value.schema)) {
|
|
180
198
|
this.assigned_data.field_config = new_value;
|
|
181
199
|
}
|
|
182
200
|
|
|
@@ -196,7 +214,7 @@ Field.enforceProperty(function config(new_value, old_value) {
|
|
|
196
214
|
}
|
|
197
215
|
|
|
198
216
|
if (new_value && new_value.constructor && new_value.constructor.type_name) {
|
|
199
|
-
this.field_type = new_value.constructor.type_name;
|
|
217
|
+
this.field_type = new_value.constructor.type_path || new_value.constructor.type_name;
|
|
200
218
|
} else if (new_value) {
|
|
201
219
|
this.field_type = null;
|
|
202
220
|
}
|
|
@@ -209,10 +227,16 @@ Field.enforceProperty(function config(new_value, old_value) {
|
|
|
209
227
|
*
|
|
210
228
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
211
229
|
* @since 0.1.0
|
|
212
|
-
* @version 0.
|
|
230
|
+
* @version 0.3.0
|
|
213
231
|
*/
|
|
214
232
|
Field.enforceProperty(function schema(new_value, old_value) {
|
|
215
233
|
|
|
234
|
+
let forced_value = !!new_value;
|
|
235
|
+
|
|
236
|
+
if (!new_value && this.assigned_data?.schema) {
|
|
237
|
+
new_value = this.assigned_data.schema;
|
|
238
|
+
}
|
|
239
|
+
|
|
216
240
|
if (!new_value) {
|
|
217
241
|
// See if this is in a schema field
|
|
218
242
|
if (this.alchemy_field_schema) {
|
|
@@ -238,6 +262,10 @@ Field.enforceProperty(function schema(new_value, old_value) {
|
|
|
238
262
|
}
|
|
239
263
|
}
|
|
240
264
|
|
|
265
|
+
if (forced_value) {
|
|
266
|
+
this.assignData('schema', new_value);
|
|
267
|
+
}
|
|
268
|
+
|
|
241
269
|
return new_value;
|
|
242
270
|
});
|
|
243
271
|
|
|
@@ -246,10 +274,14 @@ Field.enforceProperty(function schema(new_value, old_value) {
|
|
|
246
274
|
*
|
|
247
275
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
248
276
|
* @since 0.1.0
|
|
249
|
-
* @version 0.
|
|
277
|
+
* @version 0.3.0
|
|
250
278
|
*/
|
|
251
279
|
Field.setProperty(function is_array() {
|
|
252
280
|
|
|
281
|
+
if (this.assigned_data?.is_array != null) {
|
|
282
|
+
return this.assigned_data.is_array;
|
|
283
|
+
}
|
|
284
|
+
|
|
253
285
|
let config = this.config;
|
|
254
286
|
|
|
255
287
|
if (config) {
|
|
@@ -257,6 +289,8 @@ Field.setProperty(function is_array() {
|
|
|
257
289
|
}
|
|
258
290
|
|
|
259
291
|
return false;
|
|
292
|
+
}, function setValue(value) {
|
|
293
|
+
this.assignData('is_array', value);
|
|
260
294
|
});
|
|
261
295
|
|
|
262
296
|
/**
|
|
@@ -264,14 +298,18 @@ Field.setProperty(function is_array() {
|
|
|
264
298
|
*
|
|
265
299
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
266
300
|
* @since 0.1.3
|
|
267
|
-
* @version 0.
|
|
301
|
+
* @version 0.3.0
|
|
268
302
|
*/
|
|
269
|
-
|
|
303
|
+
Field.setProperty(function contains_schema() {
|
|
270
304
|
|
|
271
305
|
let config = this.config;
|
|
272
306
|
|
|
273
307
|
if (config) {
|
|
274
|
-
|
|
308
|
+
if (config instanceof Classes.Alchemy.Field.Schema) {
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return Classes.Alchemy.Client.Schema.isSchema(config);
|
|
275
313
|
}
|
|
276
314
|
|
|
277
315
|
return false;
|
|
@@ -345,17 +383,17 @@ Field.setProperty(function field_path_in_schema() {
|
|
|
345
383
|
*
|
|
346
384
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
347
385
|
* @since 0.1.3
|
|
348
|
-
* @version 0.
|
|
386
|
+
* @version 0.3.0
|
|
349
387
|
*
|
|
350
388
|
* @return {String}
|
|
351
389
|
*/
|
|
352
|
-
|
|
390
|
+
Field.setMethod(function getPathEntryName() {
|
|
353
391
|
|
|
354
392
|
if (this.config && this.config.name) {
|
|
355
393
|
return this.config.name;
|
|
356
394
|
}
|
|
357
395
|
|
|
358
|
-
return
|
|
396
|
+
return this.field_name;
|
|
359
397
|
});
|
|
360
398
|
|
|
361
399
|
/**
|
|
@@ -385,21 +423,17 @@ Field.setProperty(function model() {
|
|
|
385
423
|
*
|
|
386
424
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
387
425
|
* @since 0.1.0
|
|
388
|
-
* @version 0.
|
|
426
|
+
* @version 0.3.0
|
|
389
427
|
*/
|
|
390
428
|
Field.enforceProperty(function view_file(new_value, old_value) {
|
|
391
429
|
|
|
392
430
|
if (!new_value) {
|
|
393
431
|
|
|
394
432
|
let view_type = this.view_type,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (!field_view) {
|
|
398
|
-
let config = this.config;
|
|
433
|
+
field_view = this.field_view;
|
|
399
434
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
435
|
+
if (!field_view) {
|
|
436
|
+
field_view = this.getFieldType().replaceAll('.', '_');
|
|
403
437
|
}
|
|
404
438
|
|
|
405
439
|
new_value = this.generateTemplatePath('inputs', view_type, field_view);
|
|
@@ -441,7 +475,7 @@ Field.enforceProperty(function wrapper_file(new_value, old_value) {
|
|
|
441
475
|
*
|
|
442
476
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
443
477
|
* @since 0.1.0
|
|
444
|
-
* @version 0.
|
|
478
|
+
* @version 0.3.0
|
|
445
479
|
*/
|
|
446
480
|
Field.setProperty(function view_files() {
|
|
447
481
|
|
|
@@ -472,6 +506,9 @@ Field.setProperty(function view_files() {
|
|
|
472
506
|
return false;
|
|
473
507
|
}
|
|
474
508
|
|
|
509
|
+
// Fallback to the fallback
|
|
510
|
+
result.push(this.generateTemplatePath('inputs', view_type, 'fallback'));
|
|
511
|
+
|
|
475
512
|
// Fallback to a simple string input
|
|
476
513
|
result.push(this.generateTemplatePath('inputs', view_type, 'string'));
|
|
477
514
|
|
|
@@ -524,21 +561,46 @@ Field.setProperty(function wrapper_files() {
|
|
|
524
561
|
return result;
|
|
525
562
|
});
|
|
526
563
|
|
|
564
|
+
/**
|
|
565
|
+
* Get the original value container
|
|
566
|
+
*
|
|
567
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
568
|
+
* @since 0.3.0
|
|
569
|
+
* @version 0.3.0
|
|
570
|
+
*/
|
|
571
|
+
Field.setAssignedProperty(function original_value_container() {
|
|
572
|
+
|
|
573
|
+
if (this.assigned_data.original_value_container != null) {
|
|
574
|
+
return this.assigned_data.original_value_container;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
let form = this.alchemy_form;
|
|
578
|
+
|
|
579
|
+
if (form) {
|
|
580
|
+
return form.document;
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
|
|
527
584
|
/**
|
|
528
585
|
* Get the original value
|
|
529
586
|
*
|
|
530
587
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
531
588
|
* @since 0.1.0
|
|
532
|
-
* @version 0.
|
|
589
|
+
* @version 0.3.0
|
|
533
590
|
*/
|
|
534
591
|
Field.setProperty(function original_value() {
|
|
535
592
|
|
|
536
|
-
if (this.assigned_data.original_value
|
|
593
|
+
if (this.assigned_data.original_value !== undefined) {
|
|
537
594
|
return this.assigned_data.original_value;
|
|
538
595
|
}
|
|
539
596
|
|
|
540
|
-
let
|
|
541
|
-
|
|
597
|
+
let path = this.field_path_in_current_schema;
|
|
598
|
+
|
|
599
|
+
if (path == null) {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
let alchemy_field_schema = this.alchemy_field_schema;
|
|
542
604
|
|
|
543
605
|
if (alchemy_field_schema) {
|
|
544
606
|
let original_schema_value = alchemy_field_schema.original_value;
|
|
@@ -552,13 +614,13 @@ Field.setProperty(function original_value() {
|
|
|
552
614
|
return;
|
|
553
615
|
}
|
|
554
616
|
|
|
555
|
-
let
|
|
617
|
+
let original_container = this.original_value_container;
|
|
556
618
|
|
|
557
|
-
if (
|
|
558
|
-
return Object.path(
|
|
619
|
+
if (original_container) {
|
|
620
|
+
return Object.path(original_container, path);
|
|
559
621
|
}
|
|
560
622
|
}, function setOriginalValue(value) {
|
|
561
|
-
return this.
|
|
623
|
+
return this.assignData('original_value', value);
|
|
562
624
|
});
|
|
563
625
|
|
|
564
626
|
/**
|
|
@@ -566,26 +628,38 @@ Field.setProperty(function original_value() {
|
|
|
566
628
|
*
|
|
567
629
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
568
630
|
* @since 0.1.0
|
|
569
|
-
* @version 0.
|
|
631
|
+
* @version 0.3.0
|
|
570
632
|
*/
|
|
571
633
|
Field.setProperty(function value_element() {
|
|
572
634
|
|
|
573
|
-
let
|
|
635
|
+
let special_input;
|
|
574
636
|
|
|
575
637
|
// Translations always get preference
|
|
576
638
|
if (this.is_translatable) {
|
|
577
|
-
|
|
639
|
+
special_input = this.querySelector('al-field-translatable');
|
|
578
640
|
} else if (this.is_array) {
|
|
579
|
-
|
|
641
|
+
special_input = this.querySelector('al-field-array');
|
|
580
642
|
} else if (this.contains_schema) {
|
|
581
|
-
|
|
643
|
+
special_input = this.querySelector('al-field-schema');
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
let main_input = this.querySelector('.alchemy-field-value');
|
|
647
|
+
|
|
648
|
+
// If there is no main input, but there is a special input, simply use that
|
|
649
|
+
if (!main_input) {
|
|
650
|
+
return special_input;
|
|
582
651
|
}
|
|
583
652
|
|
|
584
|
-
if (!
|
|
585
|
-
|
|
653
|
+
if (!special_input) {
|
|
654
|
+
return main_input;
|
|
586
655
|
}
|
|
587
656
|
|
|
588
|
-
|
|
657
|
+
// Use the top level one
|
|
658
|
+
if (special_input.contains(main_input)) {
|
|
659
|
+
return special_input;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
return main_input;
|
|
589
663
|
});
|
|
590
664
|
|
|
591
665
|
/**
|
|
@@ -602,7 +676,7 @@ Field.setProperty(function value() {
|
|
|
602
676
|
if (element) {
|
|
603
677
|
let value = element.value;
|
|
604
678
|
|
|
605
|
-
if (this.config) {
|
|
679
|
+
if (this.config?.castContainedValues) {
|
|
606
680
|
value = this.config.castContainedValues(value);
|
|
607
681
|
}
|
|
608
682
|
|
|
@@ -615,7 +689,7 @@ Field.setProperty(function value() {
|
|
|
615
689
|
|
|
616
690
|
let has_changed = !Object.alike(this[LAST_SET_VALUE], value);
|
|
617
691
|
|
|
618
|
-
if (this.original_value
|
|
692
|
+
if (this.original_value === undefined) {
|
|
619
693
|
this.original_value = value;
|
|
620
694
|
}
|
|
621
695
|
|
|
@@ -650,8 +724,93 @@ Field.setProperty(function value_to_render() {
|
|
|
650
724
|
}
|
|
651
725
|
});
|
|
652
726
|
|
|
727
|
+
/**
|
|
728
|
+
* Get the placeholder for empty values (if any)
|
|
729
|
+
*
|
|
730
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
731
|
+
* @since 0.3.0
|
|
732
|
+
* @version 0.3.0
|
|
733
|
+
*/
|
|
734
|
+
Field.setProperty(function allow_empty_value_placeholder() {
|
|
735
|
+
return !!(this.applied_options?.empty_value_placeholder ?? true);
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Set the value container (like the `Document` instance) the value came from.
|
|
740
|
+
* Will only be set if there is no `alchemy_form` available.
|
|
741
|
+
*
|
|
742
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
743
|
+
* @since 0.3.0
|
|
744
|
+
* @version 0.3.0
|
|
745
|
+
*/
|
|
746
|
+
Field.setMethod(function rememberOriginalValueContainer(container) {
|
|
747
|
+
|
|
748
|
+
if (!container) {
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (this.alchemy_form) {
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
this.original_value_container = container;
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Create the empty value placeholder text
|
|
761
|
+
*
|
|
762
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
763
|
+
* @since 0.3.0
|
|
764
|
+
* @version 0.3.0
|
|
765
|
+
*
|
|
766
|
+
* @return {string|HTMLElement|Microcopy}
|
|
767
|
+
*/
|
|
768
|
+
Field.setMethod(function createEmptyValuePlaceholderText() {
|
|
769
|
+
|
|
770
|
+
let microcopy = this.applied_options?.empty_value_placeholder;
|
|
771
|
+
|
|
772
|
+
if (microcopy) {
|
|
773
|
+
return microcopy;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
microcopy = Classes.Alchemy.Microcopy('empty-value-placeholder', {
|
|
777
|
+
field_name : this.field_name,
|
|
778
|
+
model_name : this.model,
|
|
779
|
+
field_type : this.getFieldType(),
|
|
780
|
+
zone : this.zone,
|
|
781
|
+
path : this.config?.path_in_document,
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
return microcopy;
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Get variables needed to render this
|
|
789
|
+
*
|
|
790
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
791
|
+
* @since 0.3.0
|
|
792
|
+
* @version 0.3.0
|
|
793
|
+
*/
|
|
794
|
+
Field.setMethod(function prepareRenderVariables() {
|
|
795
|
+
|
|
796
|
+
let value = this.value_to_render,
|
|
797
|
+
value_is_empty = value == null || value === '' || (Array.isArray(value) ? value.length == 0 : false);
|
|
798
|
+
|
|
799
|
+
let result = {
|
|
800
|
+
alchemy_field : this,
|
|
801
|
+
field_context : this,
|
|
802
|
+
view_files : this.view_files,
|
|
803
|
+
wrapper_files : this.wrapper_files,
|
|
804
|
+
value,
|
|
805
|
+
value_is_empty,
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
return result;
|
|
809
|
+
});
|
|
810
|
+
|
|
653
811
|
/**
|
|
654
812
|
* Apply options
|
|
813
|
+
* (Like options from a FieldConfig instance)
|
|
655
814
|
*
|
|
656
815
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
657
816
|
* @since 0.1.12
|
|
@@ -16,6 +16,24 @@ const FieldArray = Function.inherits('Alchemy.Element.Form.FieldCustom', 'FieldA
|
|
|
16
16
|
*/
|
|
17
17
|
FieldArray.setTemplateFile('form/elements/alchemy_field_array');
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Minimum amount of values (in case of an array)
|
|
21
|
+
*
|
|
22
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
23
|
+
* @since 0.3.0
|
|
24
|
+
* @version 0.3.0
|
|
25
|
+
*/
|
|
26
|
+
FieldArray.setAttribute('min-entry-count', {type: 'number'});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Maximum amount of values (in case of an array)
|
|
30
|
+
*
|
|
31
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
32
|
+
* @since 0.3.0
|
|
33
|
+
* @version 0.3.0
|
|
34
|
+
*/
|
|
35
|
+
FieldArray.setAttribute('max-entry-count', {type: 'number'});
|
|
36
|
+
|
|
19
37
|
/**
|
|
20
38
|
* Get the live value
|
|
21
39
|
*
|
|
@@ -53,6 +71,10 @@ FieldArray.setMethod(function introduced() {
|
|
|
53
71
|
|
|
54
72
|
const that = this;
|
|
55
73
|
|
|
74
|
+
if (this.max_entry_count === 1) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
this.onEventSelector('click', '.remove', function onClick(e) {
|
|
57
79
|
|
|
58
80
|
e.preventDefault();
|