Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Can not set "method" dynamically #80

Open
eximius313 opened this issue Jan 31, 2016 · 6 comments
Open

Can not set "method" dynamically #80

eximius313 opened this issue Jan 31, 2016 · 6 comments

Comments

@eximius313
Copy link

When I have a form like this:

<form action="{{actionUrl}}" is="ajax-form" method="delete" id="myForm">
    <button type="submit" dialog-confirm>Submit</button>
</form>

Form works well and submits DELETE request under the URL represented by actionUrl
But when I do like this:

<form action="{{actionUrl}}" is="ajax-form" method="{{method}}" id="myForm">
    <button type="submit" dialog-confirm>Submit</button>
</form>

Form submits GET request under actionUrl even though I set it to delete

@rnicholus
Copy link
Owner

That's correct. The custom element does not current have an attributeChangedHandler function to monitor changes to the method attribute. Currently, this is only evaluated when the element is added to the DOM. If you create a pull request to add this behavior (along with a unit test), I'd be happy to merge it in.

@eximius313
Copy link
Author

I'm not feeling to be good enough in JS to write production code :(

@rnicholus
Copy link
Owner

This library is pretty small and, I think, straightforward. Just give it a go and I'll clean it up if necessary and will also take care of the unit test.

@adamvresky
Copy link

Very rough solution would be to do this in ajax-form.js

ajaxForm.acceptableMethod` = getValidMethod(ajaxForm.getAttribute('method'));

var observer = new MutationObserver(function(mutations) {
  ajaxForm.acceptableMethod = getValidMethod(ajaxForm.getAttribute('method'));
});

var observerConfig = {
    attributes: true
};

var targetNode = ajaxForm;
observer.observe(targetNode, observerConfig);

@rnicholus
Copy link
Owner

No need for a mutation observer. Instead, I would suggest registering an attributeChangedCallback.

@midgetspy
Copy link

I took a stab at this in #92

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

No branches or pull requests

4 participants