From 84212304276ef55602ac7e190f60ae5898f6dea7 Mon Sep 17 00:00:00 2001 From: Pisces000221 <1786762946@qq.com> Date: Sat, 18 Feb 2017 23:05:26 +0800 Subject: [PATCH] Add auto-complete to data file fields --- models/problem.js | 4 ++-- views/problem_data.ejs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/models/problem.js b/models/problem.js index 79be434..1f15fa0 100644 --- a/models/problem.js +++ b/models/problem.js @@ -223,8 +223,8 @@ class Problem extends Model { is_public: false, file_io: false, - file_io_input_name: 'data.in', - file_io_output_name: 'data.out' + file_io_input_name: '', + file_io_output_name: '' }, val))); } diff --git a/views/problem_data.ejs b/views/problem_data.ejs index 2e086a7..1992a32 100644 --- a/views/problem_data.ejs +++ b/views/problem_data.ejs @@ -134,5 +134,18 @@ function goDisable() { document.getElementById('file-io-input-name').disabled = true; document.getElementById('file-io-output-name').disabled = true; } + +$(document).ready(function () { + $('#file-io-input-name').on('input keyup change', function (e) { + var prob = $('#file-io-input-name').val(); + if (prob.lastIndexOf('.') !== -1) prob = prob.substring(0, prob.lastIndexOf('.')); + $('#file-io-output-name').attr('placeholder', prob + '.out'); + }); + $('#file-io-output-name').focus(function (e) { + if (!$('#file-io-output-name').val()) { + $('#file-io-output-name').val($('#file-io-output-name').attr('placeholder')); + } + }); +}); <% include footer %>