Skip to content
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

Cannot read properties of undefined (reading 'removeLoadingState') #1129

Open
cyberneticspk opened this issue Aug 29, 2023 · 0 comments
Open
Labels

Comments

@cyberneticspk
Copy link

I am trying to submit a form from a modal and the form is submitted through ajax. once the form is submitted some response is returned that regenerate the choices with the new values.

Laravel Blade Template Initial Render (Works Fine):

{{ Form::select('member_id',$members, null, ['class' => 'form-control choices','searchEnabled'=>'true', 'placeholder' => __('Select a Member')]) }}

Js Code to Target The Choices Instance:

    $("#createFemberForm").submit(function(event) {
        event.preventDefault();
        var formData = new FormData(this);;
        console.log(formData)
        $.ajax({
           method: "POST",
           url: '{{ route('members.ajax.store') }}',
           data: formData,
           dataType: "json",
           contentType: false,
           processData: false,
           success: function(response) {
              const choicesInstance = new Choices(document.getElementById('member_id'));
              var newChoices = [];
              for (var memberId in response.members) {
                 if (response.members.hasOwnProperty(memberId)) {
                    newChoices.push({
                       value: memberId,
                       label: response.members[memberId]
                    });
                 }
              }
              choicesInstance.setChoices(newChoices, 'value', 'label', true);
              var selectedValue = response.member_id;
              choicesInstance.setValueByChoice(selectedValue);
              memberModal.style.display = 'none';
           }
        });
     });

Error: Cannot read properties of undefined (reading 'removeLoadingState')

Any help??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant