framework7 icon indicating copy to clipboard operation
framework7 copied to clipboard

Submit Button-Value is not submitted on ajax-form-submit

Open cyberbeat opened this issue 9 years ago • 6 comments

This is a (multiple allowed):

  • [x] bug

  • [ ] enhancement

  • [ ] feature-discussion (RFC)

  • Framework7 Version: 1.5

  • Platform and Target: Android/iOS

I have a form with class="ajax-submit" and a submit button with a name and a value. The name-value pair of the submit button is not sent as it would be on a normal form-submit. If a submit-button is pressed, the value of that button should be submitted. If the form is submitted in another way like pressing "enter", the value of the first submit-button should be used.

I even display the page after the submit - it would be nice, if there would be a special class name for doing something like that automatically:

myApp.onPageInit('*', function(){
	$('form.ajax-submit').on('submitted', function (e) {
		mainView.router.loadContent(e.detail.data);
	});
});

cyberbeat avatar Nov 30 '16 20:11 cyberbeat

why are you using jquery selector? what is your framework selector? $$ ??

peon501 avatar Dec 01 '16 14:12 peon501

$ is my framework7 selector, I only use that (no jquery)

cyberbeat avatar Dec 01 '16 19:12 cyberbeat

It would be good to see your HTML as well as your JavaScript

ZanderBrown avatar Mar 06 '17 22:03 ZanderBrown

The problem is in the following framework7 code:

            form = $(form);
            if (form.length !== 1) return false;
        
            // Skip input types
            var skipTypes = ['submit', 'image', 'button', 'file'];
            var skipNames = [];
        
            form.find('input, select, textarea').each(function () {
            ...
            ...

Submit and image types should not be skipped! In a normal html form with a submit button like

<input type="submit" name="myname" value="my value"/>

The field "myname" is always submitted. And as I wrote in my initial request, even when submitted via the enter/return key, always the value of the first submit button is submitted. This may also be of type "image".

cyberbeat avatar Mar 12 '17 08:03 cyberbeat

I have made a codepen example, but its pretty useless, because you have to inspect, that the button name-value pair will not be submitted:

https://codepen.io/anon/pen/aWzYKr

On a normal form (without ajax) it would.

This is usefull for submitting the same form with different buttons (=different actions).

cyberbeat avatar Apr 14 '17 14:04 cyberbeat

This problem is still in v2. A fix should be simple I think:

  • if the form is submitted with a submit-button-click, then, if the button has a "name" attribute, its value should also be submitted
  • if the form is submitted without a button, always the first submit-button-name-value-pair of the form should be submitted This is how forms are handled by standard html.

cyberbeat avatar May 15 '18 18:05 cyberbeat