文档 下载安装 商店 博客 问答 主机

请问magneto2中如何改写js文件, 比如系统自带的validation验证。


#1

请问magneto2中如何改写js文件,比如系统自带的validation验证。
原js文件路径为
我的项目\vendor\magento\module-ui\view\base\web\js\lib\validation\rules.js


#2

首先你要阅读Magento2 javascript手册
知道Magento是如何书写JS的。

但是我们知道Magento2后端是默认自带验证类的,所以一般情况下,我们只需要简单修改一下就能有验证的功能.
比如我们增加一个表单验证给后端:

$fieldset->addField(
'email_from',
'text',
['name' => 'email_from', 'label' => __('Email From'), 'title' => __('Email From'), 'required' => true, 'class' => 'validate-email']
);

注意这段:

‘required’ => true, ‘class’ => ‘validate-email’

Magento2默认自带的验证类有:

min_text_length
max_text_length
max-words
min-words
range-words
letters-with-basic-punc
alphanumeric
letters-only
no-whitespace
zip-range
integer
vinUS
dateITA
dateNL
time
time12h
phoneUS
phoneUK
mobileUK
stripped-min-length
email2
url2
credit-card-types
ipv4
ipv6
pattern
validate-no-html-tags
validate-select
validate-no-empty
validate-alphanum-with-spaces
validate-data
validate-street
validate-phoneStrict
validate-phoneLax
validate-fax
validate-email
validate-emailSender
validate-password
validate-admin-password
validate-url
validate-clean-url
validate-xml-identifier
validate-ssn
validate-zip-us
validate-date-au
validate-currency-dollar
validate-not-negative-number
validate-zero-or-greater
validate-greater-than-zero
validate-css-length
validate-number
validate-number-range
validate-digits
validate-digits-range
validate-range
validate-alpha
validate-code
validate-alphanum
validate-date
validate-identifier
validate-zip-international
validate-state
less-than-equals-to
greater-than-equals-to
validate-emails
validate-cc-number
validate-cc-ukss
required-entry
checked
not-negative-amount
validate-per-page-value-list
validate-new-password
validate-item-quantity
equalTo

前端javascript部分,建议你好好搜索一下,一搜索就能出结果的。