All Projects → cretueusebiu → Vform

cretueusebiu / Vform

Licence: mit
A simple way to handle Laravel back-end validation in Vue 2.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vform

Vue Form Components
Clean & minimal vue form elements and form builder with validation
Stars: ✭ 120 (-74.84%)
Mutual labels:  vue-components, form
Vue Form Json Schema
Create forms using JSON schema. Bring your components!
Stars: ✭ 253 (-46.96%)
Mutual labels:  vue-components, form
Vue Ui For Pc
基于Vue2.x的一套PC端UI组件,包括了Carousel 跑马灯、Cascader 级联、Checkbox 多选框、Collapse 折叠面板、DatePicker 日期选择、Dialog 对话框、Form 表单、Input 输入框、InputNumber 数字输入框、Layer 弹窗层、Loading 加载、Menu 菜单、Page 分页、Progress 进度条、Radio 单选框、SelectDropDown 仿select、Switch 开关、Table 表格、Tabs 标签页、Textarea 文本框、Tooltip 文字提示、BackTop 返回顶部、steps 步骤条、Transfer 穿梭框、Tree 树形、Upload 文件上传、Lazy 图片懒加载、Loading 加载、Pagination 分页等等
Stars: ✭ 156 (-67.3%)
Mutual labels:  vue-components, form
Formvuelar
Vue form components with server-side validation in mind
Stars: ✭ 263 (-44.86%)
Mutual labels:  vue-components, form
Heyui
🎉UI Toolkit for Web, Vue2.0 http://www.heyui.top
Stars: ✭ 2,373 (+397.48%)
Mutual labels:  vue-components, form
Form Create
🔥🔥🔥 强大的动态表单生成器|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON.
Stars: ✭ 3,698 (+675.26%)
Mutual labels:  vue-components, form
Equal
🧬 Equal is a Vue 3 UI library based on TypeScript
Stars: ✭ 381 (-20.13%)
Mutual labels:  vue-components
Unform
Performance-focused API for React forms 🚀
Stars: ✭ 4,340 (+809.85%)
Mutual labels:  form
Native
Generate a form using JSON Schema and Vue.js
Stars: ✭ 382 (-19.92%)
Mutual labels:  form
Vue Persian Datetime Picker
A vue plugin to select jalali date and time
Stars: ✭ 380 (-20.34%)
Mutual labels:  vue-components
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (-0.84%)
Mutual labels:  form
Form
🚂 Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
Stars: ✭ 454 (-4.82%)
Mutual labels:  form
Vue Weui
(Deprecated) WeUI Components with love of vue.js
Stars: ✭ 414 (-13.21%)
Mutual labels:  vue-components
Revalidation
Higher Order Component for Validating Forms in React
Stars: ✭ 385 (-19.29%)
Mutual labels:  form
Vue Gl
Vue.js components rendering 3D WebGL graphics reactively with three.js
Stars: ✭ 434 (-9.01%)
Mutual labels:  vue-components
Stackscrollview
📋 iOS Form UI Builder in Swift (powered by UICollectionView)
Stars: ✭ 382 (-19.92%)
Mutual labels:  form
Vue Swatches
🎨 Help the user picking beautiful colors!
Stars: ✭ 456 (-4.4%)
Mutual labels:  vue-components
Multiitem
一个优雅的实现多类型的RecyclerView类库 支持DataBinding Form表单录入 跨多个RecyclerView拖动
Stars: ✭ 381 (-20.13%)
Mutual labels:  form
Vddl
🦄 Vue components for modifying lists with the HTML5 drag & drop API.
Stars: ✭ 407 (-14.68%)
Mutual labels:  vue-components
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (-7.13%)
Mutual labels:  vue-components

vform

Latest Version on NPM Build Status Total Downloads

A simple way to handle Laravel back-end validation in Vue. Inspired from Laravel Spark.

vform

Installation

npm i axios vform

Usage

See the included examples.

Bootstrap 4 Markup:

<template>
<div id="app">
  <form @submit.prevent="login" @keydown="form.onKeydown($event)">
    <div class="form-group">
      <label>Username</label>
      <input v-model="form.username" type="text" name="username"
        class="form-control" :class="{ 'is-invalid': form.errors.has('username') }">
      <has-error :form="form" field="username"></has-error>
    </div>

    <div class="form-group">
      <label>Password</label>
      <input v-model="form.password" type="password" name="password"
        class="form-control" :class="{ 'is-invalid': form.errors.has('password') }">
      <has-error :form="form" field="password"></has-error>
    </div>

    <button :disabled="form.busy" type="submit" class="btn btn-primary">Log In</button>
  </form>
</div>  
</template>

<script>
import Vue from 'vue'
import { Form, HasError, AlertError } from 'vform'

Vue.component(HasError.name, HasError)
Vue.component(AlertError.name, AlertError)

new Vue({
  el: '#app',
  
  data () {
    return {
      // Create a new form instance
      form: new Form({
        username: '',
        password: '',
        remember: false
      })
    }
  },

  methods: {
    login () {
      // Submit the form via a POST request
      this.form.post('/login')
        .then(({ data }) => { console.log(data) })
    }
  }
})
</script>

Laravel Controller:

class LoginController extends Controller
{
    public function login(Request $request)
    {
        $this->validate($request, [
            'username' => 'required',
            'password' => 'required',
        ]);

        // ...
    }
}

Api

Form

/**
 * Indicates if the form is sent to the server.
 *
 * @var {Boolean}
 */
busy

/**
 * Indicates if the response form the server was successful.
 *
 * @var {Boolean}
 */
successful

/**
 * Contains the validation errors from the server.
 * 
 * @var {Errors}
 */
errors

/**
 * Create a new form instance.
 *
 * @param {Object} data
 */
constructor (data = {})

/**
 * Submit the from via a POST|PATCH|PUT|DELETE|GET request.
 *
 * @param  {String} url
 * @return {Promise}
 */
post|patch|put|delete|get (url)

/**
 * Clear the form errors.
 */
clear ()

/**
 * Reset the form fields.
 */
reset ()

/**
 * Fill form data.
 *
 * @param {Object} data
 */
fill (data)

Errors

/**
 * Get all the errors.
 *
 * @return {Object}
 */
all ()

/**
 * Determine if there is an error for the given field.
 *
 * @param  {String} field
 * @return {Boolean}
 */
has (field)

/**
 * Determine if there are any errors for the given fields.
 *
 * @param  {...String} fields
 * @return {Boolean}
 */
hasAny (...fields)

/**
 * Determine if there are any errors.
 *
 * @return {Boolean}
 */
any ()

/**
 * Get the first error message for the given field.
 *
 * @param  String} field
 * @return {String|undefined}
 */
get (field)

/**
 * Get all the error messages for the given field.
 *
 * @param  {String} field
 * @return {Array}
 */
getAll (field)

/**
 * Get the error message for the given fields.
 *
 * @param  {...String} fields
 * @return {Array}
 */
only (...fields)

/**
 * Get all the errors in a flat array.
 *
 * @return {Array}
 */
flatten ()

/**
 * Clear one or all error fields.
 *
 * @param {String|undefined} field
 */
clear (field)

/**
 * Set the errors object.
 *
 * @param {Object}
 */
set (errors)

/**
 * Set a specified error message.
 *
 * @param {String}
 * @param {String}
 */
set (field, message)

Bootstrap Components

Components for Bootstrap 3 and 4.

import { 
  HasError,
  AlertError,
  AlertErrors, 
  AlertSuccess
} from 'vform'

Vue.component(HasError.name, HasError)
Vue.component(AlertError.name, AlertError)
Vue.component(AlertErrors.name, AlertErrors)
Vue.component(AlertSuccess.name, AlertSuccess)

has-error

Display the validation error for a field.

<!-- Bootstrap 4 -->
<div class="form-group">
  <label>Username</label>
  <input v-model="form.username" type="text" name="username"
    class="form-control" :class="{ 'is-invalid': form.errors.has('username') }">
  <has-error :form="form" field="username"></has-error>
</div>

<!-- Bootstrap 3 -->
<div class="form-group" :class="{ 'has-error': form.errors.has('username') }">
  <label>Username</label>
  <input v-model="form.username" type="text" name="username" class="form-control">
  <has-error :form="form" field="username"></has-error>
</div>

alert-error

Show a danger alert if there are any errors.

<alert-error :form="form" message="There were some problems with your input."></alert-error>

alert-errors

Show a danger alert with the list of errors for each field.

<alert-errors :form="form" message="There were some problems with your input."></alert-errors>
<!-- Or -->
<alert-errors :form="form">There were some problems with your input.</alert-errors>

alert-success

Show a success alert on a successful request.

<alert-success :form="form" message="Your changes have been saved!"></alert-success>
<!-- Or -->
<alert-success :form="form">Your changes have been saved!</alert-success>

Changelog

Please see CHANGELOG for more information what has changed recently.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].