app/assets/javascripts/subdivision_select.js in subdivision_select-0.0.2 vs app/assets/javascripts/subdivision_select.js in subdivision_select-0.0.3
- old
+ new
@@ -1,26 +1,27 @@
var SubdivisionSelect = (function() {
+ SubdivisionSelect.subdivisionSelector = "select[data-subdivision-selector]";
+ SubdivisionSelect.countrySelector = "select[id$=country]";
+
function SubdivisionSelect(element) {
this._countrySelect = element;
this._subdivisionSelect = $(element).
closest("form").
find(SubdivisionSelect.subdivisionSelector);
};
- SubdivisionSelect.subdivisionSelector = "select.subdivision-selector";
- SubdivisionSelect.countrySelector = "select[id$=country]";
-
SubdivisionSelect.init = function () {
var klass = this;
return $(klass.countrySelector).each(function() {
return new klass(this).init();
});
};
SubdivisionSelect.prototype.init = function() {
var self = this;
+ self._enabledInputsBeforeSubmit();
$(this._countrySelect).change(function() {
$.ajax( {
url: "/subdivisions",
data: { country_code: $(this).val() }
@@ -44,9 +45,17 @@
// If there are none, make it say "none"
if (isEmpty) {
self._subdivisionSelect.append($("<option></option>").text("none"));
}
+ };
+
+ // Disabling selects means they won't POST with the form.
+ // Solution: right before submiting a form, enabled them.
+ SubdivisionSelect.prototype._enabledInputsBeforeSubmit = function() {
+ $('form').bind('submit', function() {
+ $(this).find('select').removeAttr('disabled');
+ });
};
// Not only empty the select, but:
// if the first element is blank, add a blank element before all others
SubdivisionSelect.prototype._clearSubdivisionSelect = function() {