Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/simple_form/magic_submit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ def magic_submit_button(*args, &block)
private

def bound_to_model?
# if its a string means that its bound to a model.. but if its a symbol its not...
# if its a string means that its bound to a model.. but if its a symbol its not...
return true if its_devise?

self.object_name.is_a?(String)# || self.object.present?
end

def its_devise?
self.template.controller.class.to_s.split("::").first == "Devise"
end

def got_errors
self.object.errors.count > 0 || self.template.flash.count > 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... do I get it right that if an app sets a flash message before rendering the form, the form would be considered filled in incorrectly and the submit button will display the retry message? I guess the flash messages can't be treaded as errors per se, what do you think?

end

def main_class(options = {})
options.fetch(:destructive, false) ? 'btn-destructive' : 'btn-primary'
end
Expand All @@ -49,8 +59,7 @@ def object_scope
def translate_key(key = nil)

if bound_to_model?
key ||= self.object.errors.count > 0 ? :retry : :submit

key ||= got_errors ? :retry : :submit
I18n.t("simple_form.magic_submit.#{controller_scope}.#{object_scope}.#{lookup_action}.#{key}",
default: [
:"simple_form.magic_submit.#{controller_scope}.#{lookup_action}.#{key}",
Expand Down