承接 npmweb/client-validation-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

npmweb/client-validation-generator

最新稳定版本:2.0.1

Composer 安装命令:

composer require npmweb/client-validation-generator

包简介

Server-side code to generate client-side validation, usually based on server-side validation rules from a different validation framework

README 文档

README

Server-side code to generate client-side validation, usually based on server-side validation rules from a different validation framework. Current implementation generates jQuery Validator rules on the client-side from Laravel Validator rules on the server side, but this could be extended for any combination of server-side and client-side framework.

Installation

  1. Add npmweb/client-validation-generator as a requirement to composer.json:

     {
         "require": {
             "npmweb/client-validation-generator": "^2.0"
         }
     }
    
  2. Update your packages with composer update.

  3. If you're using Laravel, comment out any existing HtmlServiceProvider in your Laravel service providers list, and add this package's instead:

     'providers' => array(
         ...
         // LaravelCollective\Html\HtmlServiceProvider::class,
         NpmWeb\ClientValidationGenerator\Laravel\HtmlServiceProvider::class,
         NpmWeb\ClientValidationGenerator\Laravel\ClientValidationServiceProvider::class,
     ),
    
  4. If you're using Laravel, publish the package's config file to your app:

     $ php artisan vendor:publish --provider="NpmWeb\ClientValidationGenerator\Laravel\ClientValidationServiceProvider"
    

Usage

Once it's set up, how to use it depends on what kind of model you're using:

  • If you're using Ardent, when you call Form::model() or Form::close() (depending on a setting), pass validate="true", and a <script /> tag will be outputted with your generated client-side validation rules.
  • If you're using some other method of validation, call Form::clientValidation() and pass in the array of validation rules, and the <script /> tag will be outputted with your generated client-side validation rules.

To configure how this works, edit the config file app/config/client-validation.php. It has the following values:

  • 'driver': what driver to use. The only built-in one is 'jquery'
  • 'useRequireJs': true if the required JS libraries should be loaded via require.js; false if they will already be loaded some other way by your application's code, like a plain <script /> tag
  • 'packageName': when using require.js, the names of the packages to load
  • 'useDocumentReady': whether the validation setup JS code should be run after the document has fully loaded, using jQuery's document ready. If false, will run immediately.
  • 'codeAtEnd': whether the <script /> tag to load the validation should come at the start or end of the <form /> tag. Defaults to the start.
  • 'functionName': the name of the function to call; allows, for example, calling libraries that extend jQuery validator
  • 'ruleMappings': specifies how server-side validation rules should be translated to client-side ones (see below for details)

Rule Mappings

In the config file, 'ruleMappings' is an associative array. The key is the server-side validation rule name, and the value specifies how to generate the client-side rule.

In the simplest case, if the value is a string, the rule is carried over exactly from server to client. This string can be the same rule name as the key/server-side or a different one.

If the value is an associative array, several keys can be set:

  • 'name': the name of the client-side rule

  • 'param': a function defining what the parameter to the rule should be. This function receives the server-side parameter, and it can be transformed. For example, maybe the server-side rule is 'same' with a param of 'otherField', and the client-side rule needs to be 'equalTo' with a param of 'input[name=otherField]'. This could be accomplished with the following:

      'param' => function( $param ) {
          return 'input[name=' . $param . ']';
      },
    
  • 'fieldOverride: this lets you override the field the rule is set on. For example, maybe you have an email field and an email_confirmation field. On the server side, maybe the rule exists on the email field, but on the client-side you want the rule to exist on the email_confirmation field. You could accomplish that with the following:

      'fieldOverride' => function( $param, $field ) {
          return $field.'_confirmation';
      },
    

License

This code is open-sourced under the MIT license. For more information, see the LICENSE file.

npmweb/client-validation-generator 适用场景与选型建议

npmweb/client-validation-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.64k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 npmweb/client-validation-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 npmweb/client-validation-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 npmweb/client-validation-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 7
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-08