Remove state select box

I'm not against putting this back, however, it doesn't work quite as one
would expect, so I'm removing it as its functionality is more confusing
that working.

Is this really the best way to address this?

If you unselect AU, then it never comes back.  It leaves its value in
the textbox pre-filled if it ever got a value, leaving the field
pre-filled with an Aus state even if the person is New Zealand.

Most of our attendees are from but a few countries, we should make these
equal effort to fill in.
This commit is contained in:
Sachi King 2017-04-23 17:32:38 +10:00
parent 0dfe52d19d
commit b9510fed67
2 changed files with 0 additions and 82 deletions

View file

@ -27,6 +27,3 @@ class ProfileForm(forms.ModelForm):
field_classes = { field_classes = {
"of_legal_age": YesNoField, "of_legal_age": YesNoField,
} }
class Media:
js = ("lca2017/js/profile_form.js", )

View file

@ -1,79 +0,0 @@
AU_STATES = {
"ACT": "Australian Capital Territory",
"NSW": "New South Wales",
"NT": "Northern Territory",
"QLD": "Queensland",
"SA": "South Australia",
"TAS": "Tasmania",
"VIC": "Victoria",
"WA": "Western Australia",
}
function profile_form() {
selects = $("select");
for (var i=0; i<selects.length; i++) {
select = selects[i];
id = select.id;
if (!id.endsWith("country")) {
continue;
}
parts = id.split("-");
_id = parts[parts.length - 1];
prefix = parts.slice(0, parts.length - 1).join("-");
mutate_state(select, prefix);
$(select).change(function() { mutate_state(select, prefix) })
}
}
function mutate_state(country_select, prefix) {
id = prefix + "-state";
var $state = $("#" + id);
var $select = $(country_select);
var $parent = $state.parent();
state = $state.val();
state_field_name = $state.attr("name");
country = $select.val()
$state.remove();
console.log($parent);
if (country == "AU") {
$p = $("<select>");
$p.append($("<option>").attr({
"value": "",
}).text("Select a state..."));
for (var state_key in AU_STATES) {
$opt = $("<option>").attr({
"value": state_key,
});
$opt.text(AU_STATES[state_key]);
$p.append($opt);
}
$parent.attr("class", "form-field select");
} else {
// state textfield
$p = $("<input>").attr({
"type": "text",
"maxlength": 256,
});
$parent.attr("class", "form-field");
}
$p.attr({
"id": id,
"name": state_field_name,
});
$p.val(state);
$parent.append($p);
}
function __defer_profile_form() {
if (window.jQuery) {
profile_form();
} else {
setTimeout(__defer_profile_form(), 50);
}
}
__defer_profile_form();