1.0.14 • Published 8 months ago

@dpsys/ajax-form v1.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Install: npm i @dpsys/ajax-form

Usage

This example uses Axios. Use different ajax call implementation if needed.

Given form:

<form name="my_form" method="post">

    <input type="text" name="form[something]" required="required">
	            
    <button type="submit" name="form[submit]">Submit</button>
    
</form>

Then in js:

import ajaxForm from '@dpsys/ajax-form';
import axios from 'axios';

ajaxForm.get('my_form').submitCallback = (formInstance, formData) =>
{
	formData.append('some_value', 54685);

	axios.post('/some-route', formData)
	.then( async (response) => 
	{							
		if (response.data.formErrors)
		{				
			formInstance.showErrors(response.data.formErrors);
		}			
		else if (response.data.success)
		{
			...

			formInstance.reset();
		}
	});
};

Methods

get(form)

form - existing Node or string (CSS selector or value of the name attribute)

showErrors(errors)

Inserts a span element after the input field, containing the error message.

errors - Array containing objects of structure: {field_id: String, message: String}

1.0.14

8 months ago

1.0.13

10 months ago

1.0.12

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago