Results 1 to 1 of 1

Thread: Required field is not marked

  1. #1
    Junior Member
    Join Date
    Apr 2018
    Posts
    1

    Required field is not marked

    Hi everyone,
    I am Java developer, and new to Bootstrap. I know how to use html, css, js, jquery etc.
    I got project done by some people I cannot contact, and I tried to follow the logic of already written files, and to add some new input fields, remove few others and set some fields to be required.

    There wsa list of required fields from before - but when I added mine, it did not show the * sign.
    CAn someone see what is wrong in this file:
    Code:
    /**
     * Created by tamaram on 6/9/16.
     */
    
    define (function (require){
       'use strict';
    
        require('bootstrap-datepicker');
        require('realperson');
    
        var Backbone = require('backbone'),
            templateFile = require('text!templates-v2/registration-template.html'),
            ResendActivationModel = require('models-v2/ResendActivationLinkModel'),
            ResendActivationView = require('views-v2/ResendActivationLinkView'),
            TermsAndConditionsView = require('views-v2/TermsAndConditionsView'),
            InfoMessageView = require('views-v2/InfoMessageView'),
            _ = require('underscore'),
            helper = require('helper'),
            view = Backbone.View.extend({
                id: 'modalContainer',
                className: 'modal fade',
                events: {
                    'submit #registrationForm': 'registerPlayer',
                    'shown.bs.modal': 'afterRender',
                    'hidden.bs.modal': 'removeModal',
                    'click #resendActivationLink': 'showResendActivationLinkModal',
                    'click #termsAndConditions': 'showTermsAndConditions'
                },
                initialize: function () {
                    this.load();
                },
                render: function () {
                    var self = this,
                        template = _.template(templateFile, {
                            countries: this.countries,
                            helper:helper
                        });
    
                    this.$el.html(template);
    
                    return this;
                },
                load: function () {
                    this.listenTo(this.model, 'invalid', this.showErrors);
                    this.listenTo(this.model, 'change', this.hideErrors);
    
                    this.countries = helper.getCountries();
    
                    this.render();
                },
                afterRender: function () {
    
                    var fields = helper.getFormSettings('registration');
    
                    this.requiredFields = fields.REQUIRED;
    
                    this.markRequiredFields();
    
                    $('#captcha').realperson();
    
                    $('#dateOfBirthStr').datepicker({
                        autoclose: true
                    });
                },
                show: function () {
                    this.$el.modal({
                        backdrop: 'static'
                    });
                },
                removeModal: function () {
                    this.$el.data('bs.modal', null);
                    this.$el.remove();
                },
                registerPlayer: function (e) {
                    e.preventDefault();
    
                    var self = this,
                        firstName = $("#firstName").val(),
                        lastName = $("#lastName").val(),
                        alias = $("#alias").val(),
                        bankAccount = $("#bankAccount").val(),
                        dateOfBirthStr = $("#dateOfBirthStr").val(),
                        country = $("#country").val(),
                        city = $("#city").val(),
                        zip = $("#zip").val(),
                        address = $("#address").val(),
                        phoneNumber = $("#phoneNumber").val(),
                        municipalCode = $("#municipalCode").val(),
                        uid = $("#uid").val(),
                        email = $("#email").val(),
                        password = $("#password").val(),
                        repeatedPassword = $("#repeatedPassword").val(),
                        voucherNumber = $("#voucherNumber").val(),
                        over18 = $("#over18").is(":checked"),
                        captcha = $("#captcha").val();
    
                    self.startAnimation();
    
                    this.model.save({
                        'firstName': firstName,
                        'lastName': lastName,
                        'alias': alias,
                        'bankAccount': bankAccount,
                        'dateOfBirthStr': dateOfBirthStr,
                        'country': country,
                        'city': city,
                        'zip': zip,
                        'address': address,
                        'phoneNumber': phoneNumber,
                        'municipalCode': municipalCode,
                        'uid': uid,
                        'email': email,
                        'password': password,
                        'repeatedPassword': repeatedPassword,
                        'voucherNumber': voucherNumber,
                        'over18': over18,
                        'captcha': captcha,
                        'requiredFields': this.requiredFields
                        }, {
                            success: function (response) {
                                var successMessage = polyglot.t('successfullRegistration1') + self.model.get('email') + polyglot.t('successfullRegistration2');
    
                                if (helper.isErr(response.attributes)) {
                                    self.stopAnimation();
                                    $(".field-error").remove();
                                    for (var key in response.attributes.data.errorMap){
                                        $("#field-" + key).append('<span class="field-error">' + response.attributes.data.errorMap[key] + '</span>');
                                    }
                                } else {
                                    self.stopAnimation();
                                    self.showInfoMessageModal(polyglot.t('successTitle'), successMessage);
                                }
                            },
                            error: function (response) {
                                self.stopAnimation();
                                var message = helper.getSafe(response.attributes, 'message');
                                self.showInfoMessageModal(polyglot.t('errorTitle'), message);
                            }
                        });
    
                },
                showErrors: function (model, errors, options) {
                    var self = this;
    
                    self.stopAnimation();
    
                    _.each(errors, function (error){
                        var controlField;
                        if(error.name == 'title' || error.name == 'over18'){
                            controlField = $('#field-' + error.name);
                        }else{
                            controlField = $('#' + error.name);
                        }
    
                        controlField.css('border', '1px solid #ff9292');
    
                        if(typeof error.message != 'undefined'){
                            $("#field-" + error.name).append('<span class="field-error">' + error.message + '</span>')
                        }
    
                    }, this);
                },
                hideErrors: function (errors) {
                    for(var name in errors.changed) {
    
                        if(name == 'title' || name == 'over18'){
                            this.$('#field-' + name).css('border', 'none');
                        }else{
                            this.$('#' + name).css('border', '1px solid #ccc');
                        }
    
                        $(".field-error").remove();
                    }
                },
                markRequiredFields: function () {
                    _.each(this.requiredFields, function(field){
                        $('#field-' + field).append('<span class="fa fa-asterisk form-control-feedback required-field-asterisk"></span>');
                    });
                },
                showResendActivationLinkModal: function () {
                    this.removeModal();
                    var resendActivationView = new ResendActivationView({model: new ResendActivationModel()});
                    resendActivationView.show();
                },
                showTermsAndConditions: function () {
                    $("#registrationModalContent").hide();
                    var termsAndConditionsView = new TermsAndConditionsView();
                    termsAndConditionsView.show($("#registrationModalDialog"), true);
                },
                showInfoMessageModal: function (title, message) {
                    this.$el.modal('hide');
                    this.$el.on('hidden.bs.modal', function (){
                        var infoMessageView = new InfoMessageView();
                        infoMessageView.show(title, message);
                    });
                },
                startAnimation: function () {
                    var saveBtn = $('#registerPlayer');
                    saveBtn.attr('disabled', 'disabled');
                    saveBtn.prepend('<span class="fa fa-spinner fa-spin" style="padding: 0px 10px; margin-left: -34px;"></span>');
                },
                stopAnimation: function () {
                    var saveBtn = $('#registerPlayer');
                    saveBtn.removeAttr('disabled');
                    saveBtn.find('span').remove();
                }
    
            });
    
        return view;
    });
    There is that function:
    markRequiredFields: function () {
    _.each(this.requiredFields, function(field){
    $('#field-' + field).append('<span class="fa fa-asterisk form-control-feedback required-field-asterisk"></span>');
    } );
    },
    I have my_template_page and my input field is:
    <div class="form-group has-feedback">
    <div id="field-bankAccount" class="col-lg-12">
    <input type="text" id="bankAccount" class="form-control input-field-padding" name="bankAccount" placeholder="<%= polyglot.t('bankAcc') %>" />
    </div>
    </div>
    Thank you. I really need urgent help. Ofcourse, there are other file in connection with this, but, please, if someone can contact me via Skype, I would really appreciate it.
    Last edited by ganna04; 04-05-2018 at 03:52 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •