@client-side-validations/simple-form

中文文档
19.0.0发布于 2026/07/05MITESM + CJS零依赖近 30 天下载 1.2万

Client Side Validations Simple Form plugin

原始使用文档
文档目录9 节
  1. Installation
  2. JavaScript file
  3. Migration Guide
  4. Removing jQuery Dependency
  5. Usage
  6. Authors
  7. Versioning
  8. Want to help?
  9. Legal

ClientSideValidations-SimpleForm

Gem Version npm version Ruby Build Status JavaScript Build Status Maintainability Coverage Status

Simple Form plugin for ClientSideValidations

Installation

In your Gemfile add the following:

gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'

Order matters here. simple_form and client_side_validations need to be required before client_side_validations-simple_form.

Follow the remaining installation instructions for ClientSideValidations

JavaScript file

Instructions depend on your technology stack.

This package extends the jQuery-free, DOM-first ClientSideValidations runtime.

When using Webpacker

Make sure that you are requiring Client Side Validations before the Simple Form plugin.

Add the following package:

yarn add @client-side-validations/simple-form

Then, according to the CSS framework and module system you are using, add one of the following lines to your app/javascript/packs/application.js pack:

// No framework / Generic frameworks / Bootstrap 3 with `import` syntax
import '@client-side-validations/simple-form'

// Bootstrap 4+ with `import` syntax
import '@client-side-validations/simple-form/dist/simple-form.bootstrap4.esm'

// No framework / Generic frameworks / Bootstrap 3 with `require` syntax
require('@client-side-validations/simple-form')

// Bootstrap 4+ with `require` syntax
require('@client-side-validations/simple-form/dist/simple-form.bootstrap4.esm')

When using Sprockets

Make sure that you are requiring Client Side Validations before the Simple Form plugin.

According to the web framework you are using, add one of the following lines to your app/assets/javascripts/application.js, after //= require rails.validations

// No framework / Generic frameworks / Bootstrap 3
//= require rails.validations.simple_form

// Bootstrap 4+
//= require rails.validations.simple_form.bootstrap4

If you need to copy the asset files from the gem into your project, run:

rails g client_side_validations:copy_assets

Note: If you run copy_assets, you will need to run it again each time you update this project.

Migration Guide

Removing jQuery Dependency

client_side_validations-simple_form now plugs into the DOM-first ClientSideValidations runtime and no longer assumes jQuery is present.

Follow the main ClientSideValidations migration guide for the public API changes. In particular, load the current DOM-first ClientSideValidations bundle before loading this package, and update any custom code that still expects jQuery-wrapped objects.

Custom Simple Form builders now receive native DOM elements in their add and remove hooks, so custom overrides should use DOM APIs such as .closest(), .querySelector(), and .classList.

If you vendor the compiled assets with rails g client_side_validations:copy_assets, run that generator again after upgrading so the copied Simple Form assets stay in sync with the current ClientSideValidations bundle.

Usage

The usage is the same as ClientSideValidations, just pass validate: true to the form builder

<%= simple_form_for @book, validate: true do |book| %>
  <%= book.input :name %>
<% end %>

Per-input options are done with :validate

<%= book.input :name, validate: { presence: true, uniqueness: false } %>

Authors

Brian Cardarella

Geremia Taglialatela

We are very thankful for the many contributors

Versioning

This gem follows Semantic Versioning

Want to help?

Please do! We are always looking to improve this gem. Please see our Contribution Guidelines on how to properly submit issues and pull requests.

DockYard, LLC © 2012-2023

@dockyard

Licensed under the MIT license

版本与发布记录

@client-side-validations/simple-form 共发布 12 个版本,首次发布于 2019/08/25;过去 12 个月发布了 3 个版本。

版本发布日期距今
19.0.0latest2026/07/054 个月前
18.0.02026/04/196 个月前
17.0.02026/01/0710 个月前
0.4.02023/09/023 年前
0.3.12021/10/075 年前
0.3.02021/10/025 年前

关于 @client-side-validations/simple-form 的常见问题

@client-side-validations/simple-form 是什么?

Client Side Validations Simple Form plugin

如何安装 @client-side-validations/simple-form?

在项目目录运行 npm install @client-side-validations/simple-form,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@client-side-validations/client-side-validations(>=25.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@client-side-validations/simple-form 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/client-side-validations__simple-form 是否存在。

@client-side-validations/simple-form 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@client-side-validations/simple-form 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@client-side-validations/simple-form 可以商用吗?

@client-side-validations/simple-form 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@client-side-validations/simple-form 的下载量有多少?

根据 npm 官方下载统计,@client-side-validations/simple-form 在 2026/10/10 – 2026/11/08 这 30 天内被下载 12,448 次,日均约 415 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@client-side-validations/simple-form 还在维护吗?

最新版本 19.0.0 发布于 2026/07/05(4 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 3 个;首次发布于 2019/08/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。