mCaptcha/templates/panel/sitekey/add/ts/removeLevelButton/updateDom/updateInputs.ts

45 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-05-07 15:25:42 +03:00
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import CONST from '../../const';
import log from '../../../../../../logger';
2021-05-07 18:44:15 +03:00
/** update input IDs with new level */
2021-05-07 15:25:42 +03:00
const updateInput = (levelGroup: Element, newLevel: number) => {
const inputs = <NodeListOf<HTMLInputElement>>(
levelGroup.querySelectorAll(`.${CONST.LEVEL_INPUT_CLASS}`)
);
log.log(inputs);
inputs.forEach(input => {
if (input.id.includes(CONST.VISITOR_WITHOUT_LEVEL)) {
log.log(`${input.id}`);
log.log('changing visitor_threshold input');
const id = `${CONST.VISITOR_WITHOUT_LEVEL}${newLevel}`;
input.id = id;
input.name = id;
2021-05-07 16:07:44 +03:00
} else if (input.id.includes(CONST.DIFFICULTY_WITHOUT_LEVEL)) {
2021-05-07 15:25:42 +03:00
log.log('changing difficulty input');
const id = `${CONST.DIFFICULTY_WITHOUT_LEVEL}${newLevel}`;
input.id = id;
input.name = id;
2021-05-07 16:07:44 +03:00
} else {
throw new Error('Did you add an extra input to DOM?');
2021-05-07 15:25:42 +03:00
}
});
};
export default updateInput;