mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
ui: prevent submit if title is empty
This commit is contained in:
1 parent
24f001f666
commit
75f490a559
2 files changed
+13
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.20.4",
|
||||
"version": "4.20.5",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -247,7 +247,6 @@ export default new NamedPage(['problem_create', 'problem_edit'], (pagename) => {
|
||||
}
|
||||
$main.val(getContent(activeTab));
|
||||
function onChange(val) {
|
||||
console.log('onChange', activeTab, val);
|
||||
try {
|
||||
val = JSON.parse(val);
|
||||
if (!(val instanceof Array)) val = JSON.stringify(val);
|
||||
@@ -255,7 +254,6 @@ export default new NamedPage(['problem_create', 'problem_edit'], (pagename) => {
|
||||
const empty = /^\s*$/g.test(val);
|
||||
if (empty) delete content[activeTab];
|
||||
else content[activeTab] = val;
|
||||
console.log(content);
|
||||
if (!Object.keys(content).length) $field.text('');
|
||||
else $field.text(JSON.stringify(content));
|
||||
}
|
||||
@@ -266,4 +264,16 @@ export default new NamedPage(['problem_create', 'problem_edit'], (pagename) => {
|
||||
const val = getContent(lang);
|
||||
editor.value(val);
|
||||
});
|
||||
$('[type="submit"]').on('click', (ev) => {
|
||||
if (!$('[name="title"]').val().toString().length) {
|
||||
Notification.error(i18n('Title is required.'));
|
||||
$('body').scrollTop();
|
||||
$('html, body').animate(
|
||||
{ scrollTop: 0 },
|
||||
300,
|
||||
() => $('[name="title"]').focus(),
|
||||
);
|
||||
ev.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user