Skip to content

Commit

Permalink
Merge pull request #195 from ox-it/issue-194
Browse files Browse the repository at this point in the history
Issue #194 - disappearing text fields
  • Loading branch information
martinfilliau committed Jan 12, 2015
2 parents cc1dcca + 2cf93fa commit 40f5eb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
12 changes: 10 additions & 2 deletions static/js/form-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $(function() {
e.preventDefault();
var input = $(this).parents('.list-group-item').prev('input')
var removed_data_id = input.val();
var mainInput = input.siblings(".tt-input");
var mainInput = input.siblings('.twitter-typeahead').find(".tt-input");
input.remove();
$(this).parents('.list-group-item').remove();

Expand All @@ -29,9 +29,15 @@ $(function() {
var index = currentValues.indexOf(removed_data_id);
currentValues.splice(index, 1);
}

function showSelectedValue(mainInput, input, suggestion) {
// Make required changes to the document around mainInput to show the value held in input or given by 'suggestion'
// mainInput - jQuery element for the main visible and typeable input textfield
// input - jQuery element for the invisible value-holding input field
// suggestion - suggestion value picked
var valueKey = $(mainInput).data('valueKey');
var labelKey = $(mainInput).data('labelKey');
//use the supplied value, else retrieve from document data, else fetch from bloodhound storage
suggestion = suggestion || $(input).data('suggestion') || getSuggestionById(mainInput, $(input).prop('value'), valueKey);
var t = _.template('<div data-id="<%= ' + valueKey + ' %>" class="list-group-item list-group-item-info fade in"><a href="#"><span class="glyphicon glyphicon-remove"></span></a><%= ' + labelKey + ' %></div>');
var item = $(t(suggestion)).insertAfter(input);
Expand Down Expand Up @@ -86,8 +92,10 @@ $(function() {
}

function makeInput(sourceInput, name, value) {
//creates a hidden input field to hold the specified value.
// This must mirror the location of the hidden inputs created by the bootstrap loader
return $('<input>').
insertBefore(sourceInput).
insertBefore($(sourceInput).parent('span')).
attr('type', 'hidden').
attr('name', name).
attr('value', value);
Expand Down
19 changes: 18 additions & 1 deletion tests/edit_talk.robot
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ Scenario: initialise with correct data
page should appear text "contrib.user@users.com"

Scenario: change location
go to ${edit_talk_page('${event2_slug}')}
page should contain text "Banbury"
click on ${remove item('event-location')}
page should not contain text "Banbury"
type "Banbury" into ${field('Venue')}
${suggestion popup} should appear
${suggestion popup} should contain text "7-19 Banbury Road"
click on ${suggestion popup item('Banbury Road')}
${list group item("7-19 Banbury Road")} should be displayed

Scenario: remove location
go to ${edit_talk_page('${event2_slug}')}
page should contain text "Banbury"
click on ${remove item('event-location')}
Expand Down Expand Up @@ -57,7 +68,7 @@ Scenario: remove host and organiser
page should not contain text "Luke Skywalker"
page should not contain text "Darth Vader"

Scenario: remove topic
Scenario: change topic
go to ${edit_talk_page('${event1_slug}')}
page should appear text "Biodiversity"
page should appear text "Aquatic biodiversity"
Expand All @@ -66,7 +77,13 @@ Scenario: remove topic
click on ${remove item('event-topics')}
page should not contain text "Biodiversity"
page should not contain text "Aquatic biodiversity"
type "Animal diver" into ${field('Topics')}
${suggestion popup} should appear
${suggestion popup} should contain text "Animal diversity"
click on ${suggestion popup item('Animal diversity')}
${list group item("Animal diversity")} should be displayed
click on ${button done}
Location should be ${show_talk_page('${event1_slug}').url}
page should not contain text "Biodiversity"
page should not contain text "Aquatic biodiversity"
page should contain text "Animal diversity"

0 comments on commit 40f5eb6

Please sign in to comment.