single choice set default on embed

This commit is contained in:
Daniel Tsvetkov 2020-06-08 14:12:56 +02:00
parent f5e7f22f16
commit ac6eb101b5
3 changed files with 20 additions and 8 deletions

View File

@ -7,7 +7,7 @@
<title>Project</title> <title>Project</title>
<style type="text/css"> <style type="text/css">
body { body {
font-family: Open Sans, Arial, sans-serif; font-family: "Open Sans", Arial, sans-serif;
color: #444; color: #444;
padding: 0 1em; padding: 0 1em;
} }
@ -45,7 +45,6 @@
input, textarea { input, textarea {
padding: 0.5em; padding: 0.5em;
font-family: Open Sans, Arial sans-serif;
font-size: 1em; font-size: 1em;
box-sizing: border-box; box-sizing: border-box;
min-width: 300px; min-width: 300px;

View File

@ -1,15 +1,23 @@
<form action="{{ url_for('create_[[ name|camel_to_snake ]]') }}" method="post"> <form action="{{ url_for('create_[[ name|camel_to_snake ]]') }}" method="post">
<input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('list_[[ name|camel_to_snake ]]') }}"/> <input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('list_[[ name|camel_to_snake ]]') }}"/>
<table>
[%- for column in columns %] [%- for column in columns %]
<tr><td>
<label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>: <label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>:
</td><td>
[%- if column.type in ['relationship'] %] [%- if column.type in ['relationship'] %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]" [%- if column.multiple %]multiple <select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]" [% if column.multiple %]multiple
name="_m_n_[[ column.name|pluralize ]]"[% else %]name="[[ column.name ]]_id"[%- endif %]> name="_m_n_[[ column.name|pluralize ]]"[% else %]name="[[ column.name ]]_id"[%- endif %]>
[%- if not column.secondary %] [%- if not column.secondary %]
<option selected="selected">Choose...</option> <option selected="selected">Choose...</option>
[%- endif %] [%- endif %]
{%- for sub_instance in model_views.[[ column.name ]].model.query.all() %} {% if instance.[[ column.name|pluralize ]] is not defined %}
<option value="{{ sub_instance.id }}" {% if instance and instance.id == sub_instance.id %}selected="selected"{% endif %}>{{ sub_instance }}</option> {% set [[ column.name|pluralize ]] = model_views.[[ column.name ]].model.query.all() %}
{% else %}
{% set [[ column.name|pluralize ]] = instance.[[ column.name|pluralize ]] %}
{% endif %}
{%- for sub_instance in [[ column.name|pluralize ]] %}
<option value="{{ sub_instance.id }}" {% if model_view.model_name == "[[ column.name ]]" and instance and instance.id == sub_instance.id %}selected="selected"{% endif %}>{{ sub_instance }}</option>
{%- endfor %} {%- endfor %}
</select> </select>
[%- elif column.type in ['choice', ] %] [%- elif column.type in ['choice', ] %]
@ -28,7 +36,8 @@
type="text" name="[[ column.name ]]" autocomplete="off" type="text" name="[[ column.name ]]" autocomplete="off"
/> />
[%- endif %] [%- endif %]
<br> </td></tr>
[%- endfor %] [%- endfor %]
</table>
<input type="submit"> <input type="submit">
</form> </form>

View File

@ -1,10 +1,13 @@
<form action="{{ url_for('update_[[ name|camel_to_snake ]]', uuid=instance.id) }}" method="post"> <form action="{{ url_for('update_[[ name|camel_to_snake ]]', uuid=instance.id) }}" method="post">
<input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}"/> <input type="hidden" name="_next" value="{{ _next or request.args.get('_next') or url_for('get_[[ name|camel_to_snake ]]', uuid=instance.id) }}"/>
<table>
[%- for column in columns %] [%- for column in columns %]
<tr><td>
<label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>: <label for="input-[[ name|camel_to_snake ]]-[[ column.name ]]">[[ column.name ]]</label>:
</td><td>
[%- if column.type in ['relationship'] %] [%- if column.type in ['relationship'] %]
<select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]" <select id="input-[[ name|camel_to_snake ]]-[[ column.name ]]"
[%- if column.multiple %]multiple name="_m_n_[[ column.name|pluralize ]]"[% else %]name="[[ column.name ]]_id"[%- endif %]> [% if column.multiple %]multiple name="_m_n_[[ column.name|pluralize ]]"[% else %]name="[[ column.name ]]_id"[% endif %]>
{%- for sub_instance in model_views.[[ column.name ]].model.query.all() %} {%- for sub_instance in model_views.[[ column.name ]].model.query.all() %}
<option value="{{ sub_instance.id }}" <option value="{{ sub_instance.id }}"
[%- if column.multiple %] [%- if column.multiple %]
@ -32,7 +35,8 @@
type="text" name="[[ column.name ]]" autocomplete="off" type="text" name="[[ column.name ]]" autocomplete="off"
/> />
[%- endif %] [%- endif %]
<br> </td></tr>
[%- endfor %] [%- endfor %]
</table>
<input type="submit"> <input type="submit">
</form> </form>