Skip to content

Commit

Permalink
working dynamic watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
hdaws committed Jan 11, 2025
1 parent 8d84712 commit a1d7b2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
5 changes: 1 addition & 4 deletions uber/templates/forms/attendee/admin_badge_flags.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,8 @@

{% block ribbons %}
<div class="row g-sm-3">
<div class="col-12">{{ form_macros.alpine_form_input(badge_flags.ribbon,alpine_props={'x-model':'badge_ribbons'}) }}</div>
<div class="col-12">{{ form_macros.alpine_form_input(badge_flags.ribbon,alpine_props={'x-model.number':'badge_ribbons'}) }}</div>
</div>
{% if staffing_info %}
{{ form_macros.toggle_fields_js(badge_flags.ribbon, [staffing_info.staffing], on_values=[c.VOLUNTEER_RIBBON], prop='checked') }}
{% endif %}
{% endblock %}

{% block group %}
Expand Down
20 changes: 19 additions & 1 deletion uber/templates/registration/attendee_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,25 @@
{% endif %}

{{ form_macros.form_validation('attendee_form', '../registration/validate_attendee', callback="updateAttendee(submit_button_name)") }}
<form novalidate method="post" action="../registration/update_attendee" id="attendee_form" x-data="{badge_placeholder: {{ attendee.placeholder | javascript_bool }}, badge_ribbons: {{ attendee.ribbon | javascript_array }}, staffing: {{ attendee.staffing | javascript_bool }}}">
<form novalidate method="post" action="../registration/update_attendee" id="attendee_form"
x-data="{
badge_placeholder: {{ attendee.placeholder | javascript_bool }},
badge_ribbons: {{ attendee.ribbon | javascript_array }},
badge_type : {{ attendee.badge_type }},
staffing: {{ attendee.staffing | javascript_bool }}
}"

x-init="$watch('badge_ribbons',
(ribbons) => {
console.log(Alpine.raw(ribbons))
if (Alpine.raw(ribbons).includes({{ c.VOLUNTEER_RIBBON }})) { staffing=true }
});
$watch('badge_type',
(btype) => {
console.log(btype);
if( btype == {{ c.STAFF_BADGE }} || btype == {{ c.CONTRACTOR_BADGE }}){ staffing = true }
})"
>
{{ csrf_token() }}
<input type="hidden" name="id" value="{{ attendee.db_id }}" />
{% include "forms/attendee/admin_badge_flags.html" %}
Expand Down
21 changes: 11 additions & 10 deletions uber/templates/registration/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,17 @@ <h4>{{ attendee.full_name }} currently owes <strong>{{ (receipt.current_amount_o
badge_type : {{ attendee.badge_type }},
staffing: {{ attendee.staffing | javascript_bool }}
}"
x-effect="
if (Alpine.raw(badge_ribbons).includes({{ c.VOLUNTEER_RIBBON }})) {
console.log('Badge ribbons include volunteer')
staffing=true
}
if(badge_type == {{ c.STAFF_BADGE }} || badge_type == {{ c.CONTRACTOR_BADGE }}){
console.log('Badge type is staff or contractor!')
staffing=true
}
"

x-init="$watch('badge_ribbons',
(ribbons) => {
console.log(Alpine.raw(ribbons))
if (Alpine.raw(ribbons).includes({{ c.VOLUNTEER_RIBBON }})) { staffing=true }
});
$watch('badge_type',
(btype) => {
console.log(btype);
if( btype == {{ c.STAFF_BADGE }} || btype == {{ c.CONTRACTOR_BADGE }}){ staffing = true }
})"
>
{{ csrf_token() }}
<input type="hidden" name="id" value="{{ attendee.db_id }}" />
Expand Down

0 comments on commit a1d7b2d

Please sign in to comment.