Skip to content

Commit

Permalink
Force response json/blob
Browse files Browse the repository at this point in the history
New option to force response to parse to json or blob, plus version
updated to 1.0.9
  • Loading branch information
amostajo committed Jun 22, 2017
1 parent 540bdc1 commit bed8642
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 18 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,20 @@ Add the component in your vue view.

List of available props to use in component:

Prop | Data Type | Default | Description
-------------- | ---------- | -------- | -----------
`action` | String | | Action URL where to send form data.
`method` | String | POST | Request method (i.e. GET or POST).
`headers` | Object | | Request headers ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`timeout` | Number | | Request headers ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`credentials` | Boolean | | Flag that indicates if request has credentials ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`emulate-http` | Boolean | | Flag that indicates if request should emulate HTTP ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`emulate-json` | Boolean | | Flag that indicates if request should emulate JSON ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`errors` | Object | Object | List of default validation rules error messages.
`id` | String | | Form given ID.
`key` | String | | Form given loop key (i.e. in case of being used inside a v-for).
Prop | Data Type | Default | Description
--------------- | ---------- | -------- | -----------
`action` | String | | Action URL where to send form data.
`method` | String | POST | Request method (i.e. GET or POST).
`headers` | Object | | Request headers ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`timeout` | Number | | Request headers ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`credentials` | Boolean | | Flag that indicates if request has credentials ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`emulate-http` | Boolean | | Flag that indicates if request should emulate HTTP ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`emulate-json` | Boolean | | Flag that indicates if request should emulate JSON ([reference](https://github.com/vuejs/vue-resource/blob/master/docs/http.md#options)).
`errors` | Object | Object | List of default validation rules error messages.
`id` | String | | Form given ID.
`key` | String | | Form given loop key (i.e. in case of being used inside a v-for).
`response-json` | Boolean | false | Forces response to be returned and parsed as JSON.
`response-blob` | Boolean | false | Forces response to be returned as Blob.

### Request

Expand Down
33 changes: 31 additions & 2 deletions dist/vue.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Alejandro Mostajo <http://about.me/amostajo>
* @copyright 10Quality <http://www.10quality.com>
* @license MIT
* @version 1.0.8
* @version 1.0.9
*/
Vue.component('vform', Vue.extend({
props:
Expand Down Expand Up @@ -127,6 +127,26 @@ Vue.component('vform', Vue.extend({
type: [String, Number],
default: undefined,
},
/**
* Flag that indicates if response needs to be converted to json.
* @since 1.0.9
* @var bool
*/
responseJson:
{
type: [String, Boolean],
default: false,
},
/**
* Flag that indicates if response needs to be converted to json.
* @since 1.0.9
* @var bool
*/
responseBlob:
{
type: [String, Boolean],
default: false,
},
},
data: function() {
return {
Expand Down Expand Up @@ -203,12 +223,21 @@ Vue.component('vform', Vue.extend({
* @since 1.0.1 Added event dispatch.
* @since 1.0.3 Added event broadcast.
* @since 1.0.4 Response errors triggers invalid event.
* @since 1.0.9 Forces response conversion to jsob or blob.
*
* @param object response Response
*/
onSubmit: function(response)
{
this.$set('response', response.data);
this.$set(
'response',
this.responseJson
? response.json()
: (this.responseBlob
? response.blob()
: response.data
)
);
this.$dispatch('vform_success');
this.$broadcast('vform_success');
if (this.response.errors !== undefined && Object.keys(this.response.errors).length > 0) {
Expand Down
Loading

0 comments on commit bed8642

Please sign in to comment.