Magento 2 Jquery Value Not actualy setting in form submit request

by Melvin   Last Updated October 11, 2018 15:09 PM

I am trying to set 2 values dynamically when a custom field is entered in the custom registration form. Here is my custom js :

require(['jquery','mage/url'],function($,urlBuilder)
    { 
        var _this = self;
        var schoolnamesJson = '';
        var schoolNameurl = urlBuilder.build('/admin/ecssalesforce/ajax/salesforcenames');
        var interval = null;
        var interval = setInterval(companyname,2000);
        function companyname(){
            var company_name= $('.admin__field').data('index','company_name').length;
            if(company_name > 0){

                completer();
                clearInterval(interval);
            }
        }

        function completer() { 
            $('input[name="customer[company_id]"]').attr('readonly',true);
            $('input[name="customer[company_name]"]').autocomplete(
        {
            source:function( request, response ){
                $.ajax({
                    type :  "POST",
                    url  :   schoolNameurl,
                    data: {'accountname':$('input[name="customer[company_name]"]').val()},
                    success: function(data)
                    {
                        if(data.hasOwnProperty('error'))
                        {
                            $('input[name="customer[company_id]"]').val('');
                            $("[aria-live=polite]").removeClass('ui-helper-hidden-accessible ');
                            //$('#add_account_id').attr('disabled','disabled');
                        }
                        else
                        {
                            $('input[name="customer[company_id]"]').val('');
                            $("[aria-live=polite]").addClass('ui-helper-hidden-accessible ');
                        }
                        _this.schoolnamesJson = data.schoolnames;
                        response(data.schoolnames);
                    }
                });
            },
            minLength: 3,
        }).autocomplete('widget').attr('id','schoolname');

            $('#schoolname').click(function()
        {
            var url = urlBuilder.build('/admin/ecssalesforce/Salesforce/GetAccount');
            var salesforceAccountId = $('input[name="customer[company_name]"]').val().trim();
            if(salesforceAccountId.length == 0)
            {
                alert('Please Enter Salesforce Account Id');
                return false;
            }

            $.ajax({
                type :  "POST",
                url: url,
                data: {'salesforce_account_id':salesforceAccountId},
                dataType: 'json',
                showLoader: true,
                success: function(data)
                {
                    if(data.status == 1){
                        var saleforceAccountId =data.saleforceAccountId

                        $('input[name="customer[company_id]"]').val(saleforceAccountId);

                    }
                    else{
                        alert(data.error);
                    }
                }
            });
        });
        }


    });

This is workingfine as expected but when i save customer , the value is not set in post request and not getting saved. What could have gone wrong.please help



Related Questions


Updated February 23, 2016 01:04 AM

Updated September 13, 2017 15:09 PM

Updated May 31, 2017 07:09 AM

Updated March 21, 2017 21:09 PM