Skip to content

Validation update #119

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

Merged
merged 10 commits into from
May 7, 2016
5 changes: 3 additions & 2 deletions expfactory/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def create_checkbox(text,id_attribute,options,classes="",required=0):
checkbox_html = '<p id="%s_options">%s</p>' %(id_attribute,text)
for n in range(len(options)):
option_id = "%s_%s" %(id_attribute,n)
checkbox_html = '%s\n<label class="%s" for="checkbox-%s">\n<input type="checkbox" id="checkbox-%s" %s class="mdl-checkbox__input %s %s" name="%s_options" value="%s">\n<span class="mdl-checkbox__label">%s</span>\n</label>' %(checkbox_html,class_names,option_id,option_id,meta,classes,required,id_attribute,options[n],options[n])
checkbox_html = '%s\n<label class="%s" for="checkbox-%s">\n<input type="checkbox" id="checkbox-%s" %s class="mdl-checkbox__input %s %s" name="%s_options" value="%s">\n<span class="mdl-checkbox__label">%s</span>\n</label>' %(checkbox_html,class_names,option_id,option_id,meta,classes,required,option_id,options[n],options[n])
return "%s<br><br><br>" %(checkbox_html)

def base_textfield(text,id_attribute,box_text=None):
Expand Down Expand Up @@ -313,9 +313,10 @@ def parse_validation(required_counts):
validation = "%s if ( state.stepIndex === %s ) {\n" %(validation,page_number)
else:
validation = "%s else if ( state.stepIndex === %s ) {\n" %(validation,page_number)
validation = "%s if (($.unique($('.page%s.required[type=number],.page3.required:text').map(function(){return this.name})).map(function() {return $('[name*=' + this + '].required[type=number], [name*=' + this + '].required:text').filter(function() { return $(this).val();}).length > 0}).get().indexOf(false) != -1) || ($.unique($('.page%s.required:not([type=number]):not(:text)').map(function(){return this.name})).map(function() {return $('[name*=' + this + '].required:checked').length > 0}).get().indexOf(false) != -1)){\nis_required($('.page%s.required:not(checked)'));\nreturn false;\n" % (validation, page_number, page_number, page_number)
validation = '%s if (($.unique($(`.page%s.required[type=number],.page%s.required:text`).map(function(){return $(this).attr(`meta-text`)})).map(function() {return $(`[meta-text*="` + this + `"].required[type=number], [meta-text*="` + this + `"].required:text`).filter(function() { return $(this).val();}).length > 0}).get().indexOf(false) != -1) || ($.unique($(`.page%s.required:not([type=number]):not(:text)`).map(function(){return $(this).attr(`meta-text`)})).map(function() {return $(`[meta-text*="` + this + `"].required:checked`).length > 0}).get().indexOf(false) != -1)){\nis_required($(`.page%s.required:not(checked)`));\nreturn false;\n' % (validation, page_number, page_number, page_number, page_number)



# If we are at the last page, passing validation should enable the submit
if page_number == pages[-1]:
validation = '%s } else {\nexpfactory_finished=true;\n' %(validation)
Expand Down