Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a button rather than transform link into button #4133

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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