Ignoring validation for last poll answer input
last input field is only deleted if there are more than three input fields and the last one is empty poll is validated only if the last input is empty, and the first three have been filled Removed duplicate remove last answer. Dont need to check that the last value is populated as we are ignoring last value Fixing poll step Placeholder text edited Fixed translations for poll answer placeholder text Removed numbers on publisher option Removed numbers in placeholder for poll answers
This commit is contained in:
parent
aa11f7c261
commit
66fcfcfcbc
5 changed files with 23 additions and 27 deletions
|
|
@ -26,11 +26,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
|||
var input_wrapper = this.$('.poll-answer:first').clone();
|
||||
var input = input_wrapper.find('input');
|
||||
|
||||
var text = Diaspora.I18n.t('publisher.option', {
|
||||
nr: this.inputCount
|
||||
});
|
||||
|
||||
input.attr('placeholder', text);
|
||||
input.attr('placeholder', Diaspora.I18n.t('publisher.add_option'));
|
||||
input.val('');
|
||||
this.$pollAnswers.append(input_wrapper);
|
||||
this.toggleRemoveAnswer();
|
||||
|
|
@ -49,7 +45,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
|||
|
||||
removeLastAnswer: function (){
|
||||
var inputs = this.$pollAnswers.find('input');
|
||||
if(inputs.length > 2) {
|
||||
if(inputs.length > 2 && !inputs[inputs.length - 1].value) {
|
||||
this.$el.find('.poll-answer:last').remove();
|
||||
}
|
||||
},
|
||||
|
|
@ -70,7 +66,7 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
|||
|
||||
validate: function(evt){
|
||||
var input = $(evt.target);
|
||||
this.validateInput(input);
|
||||
this.validatePoll();
|
||||
this.trigger('change');
|
||||
},
|
||||
|
||||
|
|
@ -94,18 +90,17 @@ app.views.PublisherPollCreator = app.views.Base.extend({
|
|||
|
||||
validatePoll: function() {
|
||||
var _this = this;
|
||||
_.each(this.$('input:visible'), function(input){
|
||||
_this.validateInput($(input));
|
||||
});
|
||||
},
|
||||
var inputs = this.$('input:visible');
|
||||
var pollValid = true;
|
||||
|
||||
isValidPoll: function(){
|
||||
var _this = this;
|
||||
|
||||
return _.every(this.$('input:visible'), function(input){
|
||||
if(_this.isValidInput($(input)))
|
||||
return true;
|
||||
_.each(inputs, function(input, i){
|
||||
// Validate the input unless it is the last one, or there are only the
|
||||
// question field and two options
|
||||
if( i !== inputs.length - 1 || inputs.length <= 3) {
|
||||
if(_this.validateInput($(input)) == false) pollValid = false;
|
||||
}
|
||||
});
|
||||
|
||||
return pollValid;
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -155,6 +155,10 @@ app.views.Publisher = Backbone.View.extend({
|
|||
var self = this;
|
||||
|
||||
if(evt){ evt.preventDefault(); }
|
||||
|
||||
// Auto-adding a poll answer always leaves an empty box when the user starts
|
||||
// typing in the last box. We'll delete the last one to avoid submitting an
|
||||
// empty poll answer and failing validation.
|
||||
this.view_poll_creator.removeLastAnswer();
|
||||
|
||||
//add missing mentions at end of post:
|
||||
|
|
@ -454,10 +458,7 @@ app.views.Publisher = Backbone.View.extend({
|
|||
_submittable: function() {
|
||||
var onlyWhitespaces = ($.trim(this.el_input.val()) === ''),
|
||||
isPhotoAttached = (this.el_photozone.children().length > 0),
|
||||
isValidPoll = this.view_poll_creator.isValidPoll();
|
||||
|
||||
// show poll errors
|
||||
this.view_poll_creator.validatePoll();
|
||||
isValidPoll = this.view_poll_creator.validatePoll();
|
||||
|
||||
return (!onlyWhitespaces || isPhotoAttached) && isValidPoll && !this.disabled;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
<div class="poll-answers">
|
||||
<div class="poll-answer control-group">
|
||||
<div class="controls">
|
||||
<input type="text" name="poll_answers[]" placeholder="{{t 'publisher.option' nr=1}}">
|
||||
<input type="text" name="poll_answers[]" placeholder="{{t 'publisher.option' }}">
|
||||
<div class="remove-answer icons-deletelabel"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="poll-answer control-group">
|
||||
<div class="controls">
|
||||
<input type="text" name="poll_answers[]" placeholder="{{t 'publisher.option' nr=2}}">
|
||||
<input type="text" name="poll_answers[]" placeholder="{{t 'publisher.option' }}">
|
||||
<div class="remove-answer icons-deletelabel"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ en:
|
|||
limited: "Limited - your post will only be seen by people you are sharing with"
|
||||
public: "Public - your post will be visible to everyone and found by search engines"
|
||||
near_from: "Posted from: <%= location %>"
|
||||
option: "Option <%= nr %>"
|
||||
add_option: "Add option"
|
||||
option: "Answer"
|
||||
add_option: "Add an answer"
|
||||
question: "Question"
|
||||
bookmarklet:
|
||||
post_something: "Post to diaspora*"
|
||||
|
|
|
|||
|
|
@ -39,6 +39,6 @@ When(/^I lose focus$/) do
|
|||
find("#publisher-poll-creator").click
|
||||
end
|
||||
|
||||
Then /^I should see an element '([^"]*)'$/ do |selector|
|
||||
Then /^I should see an element "([^"]*)"$/ do |selector|
|
||||
page.should have_css(selector)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue