tailbone/tailbone/templates/forms/deform_buefy.mako
Lance Edgar fbf3ee5cd1 Improve readonly form templates somewhat, for Buefy
progress at least, more polish needed yet
2019-05-21 12:14:49 -05:00

78 lines
2.1 KiB
Mako

## -*- coding: utf-8; -*-
<script type="text/x-template" id="buefy-form-template">
% if not form.readonly:
${h.form(form.action_url, id=dform.formid, method='post', enctype='multipart/form-data', **form_kwargs)}
${h.csrf_token(request)}
% endif
<section>
% for field in form.fields:
% if form.readonly or (field not in dform and field in form.readonly_fields):
<b-field horizontal
label="${form.get_label(field)}">
${form.render_field_value(field)}
</b-field>
% elif field in dform:
<% field = dform[field] %>
<b-field horizontal
label="${form.get_label(field.name)}"
% if field.error:
type="is-danger"
:message='${form.messages_json(field.error.messages())|n}'
% endif
>
${field.serialize(use_buefy=True)|n}
</b-field>
% endif
% endfor
</section>
% if buttons:
<br />
${buttons|n}
% elif not form.readonly and (buttons is Undefined or (buttons is not None and buttons is not False)):
<br />
<div class="buttons">
${h.submit('save', getattr(form, 'submit_label', getattr(form, 'save_label', "Submit")), class_='button is-primary')}
% if getattr(form, 'show_reset', False):
<input type="reset" value="Reset" class="button" />
% endif
% if getattr(form, 'show_cancel', True):
% if form.mobile:
${h.link_to("Cancel", form.cancel_url, class_='ui-btn ui-corner-all')}
% else:
${h.link_to("Cancel", form.cancel_url, class_='cancel button{}'.format(' autodisable' if form.auto_disable_cancel else ''))}
% endif
% endif
</div>
% endif
% if not form.readonly:
${h.end_form()}
% endif
</script>
<div id="buefy-form-app">
<buefy-form></buefy-form>
</div>
<script type="text/javascript">
const BuefyForm = {
template: '#buefy-form-template',
}
Vue.component('buefy-form', BuefyForm)
new Vue({
el: '#buefy-form-app'
})
</script>