Skip to content

Commit

Permalink
feat(ncform): Add the globalConfig.scrollToFailField to support auto …
Browse files Browse the repository at this point in the history
…scroll to the first validation

re ncform#102
  • Loading branch information
daniel-dx committed Oct 16, 2019
1 parent f5fa0be commit a78362f
Show file tree
Hide file tree
Showing 8 changed files with 4,452 additions and 2,906 deletions.
6 changes: 6 additions & 0 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
},
constants: { // Global constant configuration, can be accessed by {{$const.userName}}
userName: 'daniel'
},
scrollToFailField: { // Automatically scroll to fields that failed validation
enabled: true, // Enable this feature or not
container: 'body', // The container that has to be scrolled.
duration: 500, // The duration (in milliseconds) of the scrolling animation
offset: -80, // The offset that should be applied when scrolling.
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions CONFIG_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
},
constants: { // 全局常量配置,可在dx表达中通过{{$const.}}来访问,如{{$const.userName}}
userName: 'daniel'
},
scrollToFailField: { // 自动滚动到校验失败的字段
enabled: true, // 是否开启
container: 'body', // 滚动的容器。
duration: 500, // 滚动动画的持续时间(以毫秒为单位)
offset: -80, // 滚动时的偏移量
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/ncform-common/src/ncform-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ const ncformUtils = {
validationMsg: {},
constants: {
// 常量数据,可通过{{$const.}}访问
},
scrollToFailField: { // Automatically scroll to fields that failed validation
enabled: true, // enable this feature or not
container: 'body',
duration: 500, // The duration (in milliseconds) of the scrolling animation
offset: -80, // The offset that should be applied when scrolling.
}
};
newFieldVal.globalConfig = newFieldVal.globalConfig || {};
Expand Down
8 changes: 7 additions & 1 deletion packages/ncform-common/test/unit/ncform-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ describe('/src/ncform-utils.js', () => {
invalidFeedbackCls: ""
},
validationMsg: {},
constants: {}
constants: {},
scrollToFailField: { // Automatically scroll to fields that failed validation
enabled: true, // enable this feature or not
container: 'body',
duration: 500, // The duration (in milliseconds) of the scrolling animation
offset: -80, // The offset that should be applied when scrolling.
}
})
assert.equal(newFormSchema.properties.name.ui.label, 'name');
assert.equal(newFormSchema.properties.name.ui.showLabel, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h4>[CASE] {{ item.title }}</h4>
<div v-if="item.validPass !== undefined">valid pass: {{ item.validPass }}</div>

<button
v-if="['ignoreRulesWhenHidden is true', 'ignoreRulesWhenHidden is false'].indexOf(item.title) >= 0"
v-if="['ignoreRulesWhenHidden is true', 'ignoreRulesWhenHidden is false', 'auto scroll to first error'].indexOf(item.title) >= 0"
class="btn btn-primary"
@click="submit(item)"
>
Expand Down Expand Up @@ -191,6 +191,39 @@ <h4>[CASE] {{ item.title }}</h4>
}
}
}
},
{
id: md5('auto scroll to first error'),
title: 'auto scroll to first error',
formName: 'form_' + Math.random(),
formSchema: {
type: 'object',
properties: {
name: {
type: 'string',
rules: {
required: true
}
},
a1: {
type: 'string',
},
a2: {
type: 'string',
},
a3: {
type: 'string',
}
},
globalConfig: {
scrollToFailField: {
enabled: true,
container: 'body',
duration: 1000,
offset: -120,
}
}
}
}
]
},
Expand Down
Loading

0 comments on commit a78362f

Please sign in to comment.