Skip to content

Commit

Permalink
Generate a button rather than transform link into button
Browse files Browse the repository at this point in the history
This eliminates unnecessary code
  • Loading branch information
jcoyne committed Mar 14, 2024
1 parent f8ea9f7 commit d2f8521
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 25 deletions.
22 changes: 0 additions & 22 deletions app/javascript/feedback_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,11 @@ Blacklight.onLoad(function(){
});
}

function replaceLink(form, link) {
var attrs = {};
$.each(link[0].attributes, function(idx, attr) {
attrs[attr.nodeName] = attr.value;
});
attrs.class = 'cancel-link btn btn-link';

// Replace the cancel link with a button
link.replaceWith(function() {
return $('<button />', attrs).append($(this).contents());
});

// Cancel link should not submit form
form.find('button.cancel-link').on('click', function(e){
e.preventDefault();
});
}

Plugin.prototype = {

init: function() {
var $el = $(this.element);
var $form = $($el).find('form');
var $cancelLink = $el.find(".cancel-link");

// Replace "Cancel" link with link styled button
replaceLink($el, $cancelLink);

//Add listener for form submit
submitListener($el, $form);
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/feedback_forms/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="form-group row">
<div class="offset-sm-3 col-sm-9">
<button type="submit" class="btn btn-primary">Send</button>
<%= link_to "Cancel", :back, class:"cancel-link", data: { toggle: 'collapse', target: target } %>
<button type="button" class="cancel-link btn btn-link" data-toggle="collapse" data-target="<%= target %>">Cancel</button>
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion spec/features/connection_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
scenario 'connection form should be shown filled out and submitted' do
find('.connection-problem').click
expect(page).to have_css('#connection-form', visible: true)
expect(page).to have_css('a', text: 'Cancel')
within 'form.feedback-form' do
fill_in('resource_name', with: 'Resource name')
fill_in('problem_url', with: 'http://www.example.com/yolo')
Expand Down
1 change: 0 additions & 1 deletion spec/features/feedback_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
click_link "Feedback"
expect(page).to have_css("#feedback-form", visible: true)
expect(page).to have_css("#feedback_message", count: 1)
expect(page).to have_css("a", text: "Cancel")
within "form.feedback-form" do
fill_in("message", with: "This is only a test")
fill_in("name", with: "Ronald McDonald")
Expand Down

0 comments on commit d2f8521

Please sign in to comment.