form.pt
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<form
tal:define="style style|field.widget.style;
css_class css_class|string:${field.widget.css_class or field.css_class or ''};
item_template item_template|field.widget.item_template;
autocomplete autocomplete|field.autocomplete;
title title|field.title;
errormsg errormsg|field.errormsg;
description description|field.description;
buttons buttons|field.buttons;
use_ajax use_ajax|field.use_ajax;
ajax_options ajax_options|field.ajax_options;
formid formid|field.formid;
action action|field.action or None;
method method|field.method;"
tal:attributes="autocomplete autocomplete;
style style;
class css_class;
action action;
attributes|field.widget.attributes|{};"
id="${formid}"
method="${method}"
enctype="multipart/form-data"
accept-charset="utf-8"
class="deform ${field.bootstrap_form_style | 'form-horizontal'}"
i18n:domain="deform"
>
<!--osipkdForm Widgets-->
<div class="grid grid-cols-12 gap-y-6 md:gap-6">
<input type="hidden" name="_charset_" />
<input type="hidden" name="__formid__" value="${formid}" />
<div
tal:condition="field.error"
id="dismiss-toast"
class="toast-onload bg-lighterror border border-lighterror text-sm text-erroremphasis rounded-md dark:bg-darkerror dark:border-darkerror dark:text-error hs-removing:translate-x-3 hs-removing:opacity-0 transition duration-300"
role="alert"
>
<div class="flex gap-2 p-3">
<i class="ti ti-alert-circle text-red text-3xl"></i>
<div>
<span class="font-semibold"
>Terdapat kesalahan pada pengisian form!
</span>
<p class="text-xs text-red">${field.errormsg}</p>
</div>
<div class="ms-auto">
<button type="button" data-hs-remove-element="#dismiss-toast">
<i class="ti ti-x text-lg text-red opacity-70 leading-none"></i>
</button>
</div>
</div>
</div>
<div
tal:repeat="child field"
tal:replace="structure child.render_template(item_template)"
/>
<div class="col-span-12 md:col-span-4 md:col-start-2 gap-6">
<tal:loop tal:repeat="button buttons">
<button
tal:define="btn_disposition repeat.button.start and 'btn-primary' or 'btn-default'; btn_class button.name == 'cancel' and 'btn-light-error' or '';"
tal:attributes="disabled button.disabled if button.disabled else None;
attributes|button.attributes|{};"
id="${formid+button.name}"
name="${button.name}"
type="${button.type}"
class="btn btn-md me-3 ${btn_class}"
value="${button.value}"
tal:condition="button.type != 'link'"
>
<span
tal:condition="button.icon"
class="glyphicon glyphicon-${button.icon}"
></span>
${button.title}
</button>
<a
tal:define="btn_disposition repeat.button.start and 'btn-primary' or 'btn-default';
btn_href button.value|''"
class="btn ${button.css_class or btn_disposition}"
id="${field.formid + button.name}"
href="${btn_href}"
tal:condition="button.type == 'link'"
>
<span
tal:condition="button.icon"
class="glyphicon glyphicon-${button.icon}"
></span>
${button.title}
</a>
</tal:loop>
</div>
</div>
<script type="text/javascript" tal:condition="use_ajax">
deform.addCallback(
'${formid}',
function (oid) {
var target = '#' + oid;
var options = {
target: target,
replaceTarget: true,
success: function () {
deform.processCallbacks();
deform.focusFirstInput(target);
},
beforeSerialize: function () {
// See http://bit.ly/1agBs9Z (hack to fix tinymce-related ajax bug)
if ('tinymce' in window) {
$(tinymce.get()).each(
function (i, el) {
var content = el.getContent();
var editor_input = document.getElementById(el.id);
editor_input.value = content;
});
}
}
};
var extra_options = ${ ajax_options }| {};
$('#' + oid).ajaxForm($.extend(options, extra_options)); <!-- TAL Expression: This line initializes the AJAX form using jQuery's ajaxForm plugin, merging the default options with any extra options provided via the TAL variable ajax_options. -->
}
);
</script>
</form>