Skip to content

Commit

Permalink
Moved input existence validations to client
Browse files Browse the repository at this point in the history
  • Loading branch information
BrokenEagle committed Nov 13, 2017
1 parent af7c109 commit 9bac691
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions app/assets/javascripts/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
this.initialize_info_bookmarklet();
this.initialize_similar();
this.initialize_shortcuts();
this.initialize_submit();
$("#related-tags-button").trigger("click");
$("#find-artist-button").trigger("click");

Expand All @@ -26,6 +27,27 @@
}
}

Danbooru.Upload.initialize_submit = function() {
$("#submit-button").click(function(e) {
var error_messages = [];
if (($("#upload_file").val() === "") && ($("#upload_source").val() === "")) {
error_messages.push("Must choose file or specify source");
}
if (!$("#upload_rating_s")[0].checked && !$("#upload_rating_q")[0].checked && !$("#upload_rating_e")[0].checked) {
error_messages.push("Must specify a rating");
}
if (error_messages.length === 0) {
$("#form").trigger("submit");
$("#submit-button")[0].setAttribute("disabled","true");
$("#submit-button")[0].setAttribute("value","Submitting...");
$("#client-errors").hide();
} else {
$("#client-errors")[0].innerHTML = "<strong>Error</strong>: " + error_messages.join(", ");
$("#client-errors").show();
}
});
}

Danbooru.Upload.initialize_shortcuts = function() {
Danbooru.keydown("e", "edit", function(e) {
$("#upload_tag_string").focus();
Expand Down
4 changes: 2 additions & 2 deletions app/views/uploads/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<%= render "post", :post => @post %>
<%= render "sources/info", :source => @source %>

<%= error_messages_for "upload" %>
<div id="client-errors" class="error-messages ui-state-error ui-corner-all" style="display:none"></div>

<%= form_for(@upload, :html => {:multipart => true, :class => "simple_form", :id => "form"}) do |f| %>
<%= hidden_field_tag :url, params[:url] %>
Expand Down Expand Up @@ -116,7 +116,7 @@
</div>

<div class="input">
<%= submit_tag "Submit", :class => "large", :data => { :disable_with => "Submitting..." }, :class => "ui-button ui-widget ui-corner-all gradient" %>
<input value="Submit" id="submit-button" type="button" class="ui-button ui-widget ui-corner-all gradient">
</div>

<div id="artist-tags-container">
Expand Down

0 comments on commit 9bac691

Please sign in to comment.