Commit 21482e15 by aa.gusti

perbikan template select2_ms

1 parent 1927989d
......@@ -7,11 +7,9 @@
optgroup_class optgroup_class|field.widget.optgroup_class;
multiple multiple|field.widget.multiple;
url url|field.widget.url;
slave slave|field.widget.slave;"
tal:omit-tag="">
slave slave|field.widget.slave;" tal:omit-tag="">
<style>
.select2-selection.form-control {
padding: 0px 0px;
}
......@@ -20,10 +18,8 @@
.select2-container--default .select2-selection--single {
border: 1px solid #ccc;
}
</style>
<input type="hidden" name="__start__" value="${name}:sequence"
tal:condition="multiple" />
<input type="hidden" name="__start__" value="${name}:sequence" tal:condition="multiple" />
<select tal:attributes="
name name;
......@@ -34,18 +30,15 @@
style style;
attributes|field.widget.attributes|{};">
<tal:loop tal:repeat="item values">
<optgroup tal:condition="isinstance(item, optgroup_class)"
tal:attributes="label item.label">
<option tal:repeat="(value, description) item.options"
tal:attributes="
<optgroup tal:condition="isinstance(item, optgroup_class)" tal:attributes="label item.label">
<option tal:repeat="(value, description) item.options" tal:attributes="
selected python:field.widget.get_select_value(cstruct, value);
class css_class;
label field.widget.long_label_generator and description;
value value"
tal:content="field.widget.long_label_generator and field.widget.long_label_generator(item.label, description) or description"/>
tal:content="field.widget.long_label_generator and field.widget.long_label_generator(item.label, description) or description" />
</optgroup>
<option tal:condition="not isinstance(item, optgroup_class)"
tal:attributes="
<option tal:condition="not isinstance(item, optgroup_class)" tal:attributes="
selected python:field.widget.get_select_value(cstruct, item[0]);
class css_class;
value item[0]">${item[1]}</option>
......@@ -54,47 +47,56 @@
<script type="text/javascript">
deform.addCallback(
'${field.oid}',
function (oid) {
$('#' + oid).select2({
containerCssClass: 'form-control',
placeholder: "${str(field.widget.placeholder).replace('"','\\"')|""}" || undefined,
allowClear: "${hasattr(field.widget, 'placeholder')}",
tags: ${str(getattr(field.widget, 'tags', 'undefined')).lower()}
'${field.oid}',
function (oid) {
$('#' + oid).select2({
containerCssClass: 'form-control',
placeholder: "${str(field.widget.placeholder).replace('"','\\"')|""}" || undefined,
allowClear: "${hasattr(field.widget, 'placeholder')}",
tags: ${str(getattr(field.widget, 'tags', 'undefined')).lower()}
});
}
);
</script>
<script type="text/javascript" tal:condition="url and slave">
deform.addCallback(
'${field.oid}',
function (oid) {
$('#' + oid).change(function () {
$("#${slave}").val("");
$("#${slave}").empty();
$("#${slave}").append('<option value="" selected disabled>Pilih Data...</option>');
let value = $(this).val();
if (value) {
$.ajax({
type: "GET",
url: "${url}" + value,
success: function (res) {
if (res) {
$.each(res, function (key, value) {
$("#${slave}").append('<option value="' + key + '">' + value + '</option>');
});
} else {
$("#${slave}").empty();
'${field.oid}',
function (oid) {
$('#' + oid).change(function () {
$("#${slave}").val("");
$("#${slave}").empty();
$("#${slave}").append('<option value="" selected disabled>Pilih Data...</option>');
let value = $(this).val();
if (value) {
$.ajax({
type: "GET",
url: "${url}" + value,
success: function (res) {
if (res) {
var def_value = null;
if (res.hasOwnProperty("default")) {
values = res.values;
def_value = res.default;
}
else
values = res;
$.each(values, function (key, value) {
if (key === def_value)
$("#${slave}").append('<option value="' + key + '" selected>' + value + '</option>');
else
$("#${slave}").append('<option value="' + key + '">' + value + '</option>');
});
} else {
$("#${slave}").empty();
}
});
}
$("#${slave}").change();
});
}
});
}
$("#${slave}").change();
});
});
</script>
<input type="hidden" name="__end__" value="${name}:sequence"
tal:condition="multiple" />
</div>
<input type="hidden" name="__end__" value="${name}:sequence" tal:condition="multiple" />
</div>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!