Skip to content

Commit 48294d9

Browse files
committed
Update models example to be more accurate.
1 parent 5d8143b commit 48294d9

File tree

1 file changed

+33
-61
lines changed

1 file changed

+33
-61
lines changed

example/unicorn/templates/unicorn/models.html

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
border: red 1px solid !important;
55
}
66
</style>
7+
8+
<h3>Current flavors</h3>
9+
<ul>
10+
{% for flavor in flavors %}
11+
<li>{{ flavor.id }} - {{ flavor.name }} - {{ flavor.label }}</li>
12+
{% endfor %}
13+
</ul>
714

815
<div>
916
<h3>New Flavor (instance variable)</h3>
@@ -31,85 +38,50 @@ <h3>New Flavor (class attribute)</h3>
3138
<button unicorn:click="add_class_flavor">Add Flavor (class attribute)</button>
3239
</div>
3340

34-
<!-- Can use unicorn:model or unicorn:db -->
35-
<div unicorn:model="flavors" unicorn:db="flavor">
36-
<div unicorn:pk="">
37-
<h3>New flavor with blank PK</h3>
41+
<div>
42+
<h3>Using unicorn:db</h3>
43+
44+
<div unicorn:db="flavor">
3845
<div>
3946
<label>Name</label>
40-
<input type="text" unicorn:field.defer="name"></input>
41-
42-
<strong>Name</strong> {{ flavor.name }}
47+
<input type="text" unicorn:field.defer="name" u:dirty.class="dirty"></input>
4348
</div>
4449

4550
<div>
4651
<label>Label</label>
47-
<input type="text" unicorn:field.defer="label"></input>
48-
49-
<strong>Label</strong> {{ flavor.label }}
52+
<input type="text" unicorn:field.defer="label" u:dirty.class="dirty"></input>
5053
</div>
5154

52-
{% comment %}
53-
<label>Parent</label>
54-
<select>
55-
<option value="" selected>None</option>
56-
{% for available_flavor in available_flavors %}
57-
<option value="{{ available_flavor.pk }}" {% if instance_flavor.parent.pk == available_flavor.pk %}selected{% endif %}>{{ available_flavor.name }}</option>
58-
{% endfor %}
59-
</select>
60-
{% endcomment %}
61-
</div>
62-
<br />
63-
64-
<h3>Last 2 added flavors</h3>
65-
66-
{% for flavor in flavors %}
67-
<div unicorn:pk="{{ flavor.pk }}">
68-
<h4>PK: {{ flavor.pk }}</h4>
69-
<div>
55+
{% for flavor in flavors %}
56+
<div unicorn:pk="{{ flavor.pk }}">
57+
<h4>{{ flavor.pk }}</h4>
7058
<label>Name</label>
71-
<input type="text" unicorn:field.lazy="name" u:dirty.class="dirty"></input>
72-
73-
<strong>Name</strong> {{ flavor.name }}
74-
</div>
75-
76-
<div>
59+
<input type="text" unicorn:field.defer="name" u:dirty.class="dirty" value="{{ flavor.name }}"></input>
60+
{{ flavor.name }}
61+
<br />
62+
7763
<label>Label</label>
78-
<input type="text" unicorn:field.defer="label" u:dirty.class="dirty"></input>
79-
80-
<strong>Label</strong> {{ flavor.label }}
81-
</div>
64+
<input type="text" unicorn:field.defer="label" u:dirty.class="dirty" value="{{ flavor.label }}"></input>
65+
{{ flavor.label }}
66+
<br />
8267

83-
<div>
84-
<label>Float value</label>
68+
<label>Float</label>
8569
<input type="text" unicorn:field.defer="float_value"></input>
86-
87-
<strong>Float value</strong> {{ flavor.float_value }}
88-
</div>
70+
{{ flavor.float_value }}
71+
<br />
8972

90-
<div>
9173
<label>Decimal value</label>
9274
<input type="text" unicorn:field.defer="decimal_value"></input>
93-
94-
<strong>Decimal value</strong> {{ flavor.decimal_value }}
95-
</div>
96-
97-
<button unicorn:click="delete($model)">delete($model)</button>
98-
<br/>
75+
{{ flavor.decimal_value }}
76+
<br />
9977

100-
<!-- todo: get updating parent working correctly -->
101-
<label>Parent</label>
102-
<select>
103-
<option value="" selected>None</option>
104-
{% for available_flavor in available_flavors %}
105-
<option value="{{ available_flavor.pk }}" {% if flavor.parent.pk == available_flavor.pk %}selected{% endif %}>{{ available_flavor.name }}</option>
106-
{% endfor %}
107-
</select>
78+
<button unicorn:click="delete($model)">delete($model)</button>
79+
</div>
80+
{% endfor %}
10881
</div>
109-
{% endfor %}
11082
</div>
111-
<br />
112-
83+
84+
<br /><br />
11385
<button unicorn:click="$refresh">$refresh</button>
11486
<button unicorn:click="$reset">$reset</button>
11587
</div>

0 commit comments

Comments
 (0)