2

I am working on angularjs + magento :). In magento i cannot add ng-model to every form element as these are created dynamically, and using jquery i can get submitted data using

var data = jQuery('#product_addtocart_form').serialize();

but how can i capture the submitted data in angularjs? I also had an object of related products (selected by the customers) which i will add to this data object to. Can someone help me how to achieve this? Thanks in advance, and I apologize for my poor English .

2 Answers 2

3

If you can change the form definition in html :

<form ng-submit="submitMyForm(myFormName)" name="myFormName">

and in the controller :

$scope.submitMyForm = function(form){
    //get the form data with jquery
}

since you have no ng-model there is no way for angular to know about your models, so you have to get the forms data with jquery.

Anf if you can't change the form definition in the template then you are really stuck with using jquery for everything.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your response, yes i can edit form and now i am able to get form data in serialized format from jquery but to attach related products to it i am using parseJSON method but it give me the same result as serialized data. var data=jQuery('#product_addtocart_form').serialize(); console.log(data); var formdata=jQuery.parseJSON('"'+data+'"'); both gives me same string. can you help me with this.
@Haris little late , but why are you adding quotes to data? data is a string and this sould just work var formdata=jQuery.parseJSON(data);
0

Try to look at this tutorial and see if it can help.

http://tutsnare.com/post-form-data-using-angularjs/

1 Comment

thanx for your response but this tutorial is not using the way I HAD to follow as it is using ng-model for each element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.