Merge branch '702-Enter-auf-CCommR-abfangen'
This commit is contained in:
commit
959db324db
53
frontend/src/utils/form/enter-is-tab.js
Normal file
53
frontend/src/utils/form/enter-is-tab.js
Normal file
@ -0,0 +1,53 @@
|
||||
import { Utility } from '../../core/utility';
|
||||
|
||||
const ENTER_IS_TAB_INITIALIZED_CLASS = 'enter-as-tab--initialized';
|
||||
const AREA_SELECTOR = 'input, textarea';
|
||||
|
||||
@Utility({
|
||||
selector: '[uw-enter-as-tab]',
|
||||
})
|
||||
|
||||
export class EnterIsTab {
|
||||
_element;
|
||||
|
||||
constructor(element) {
|
||||
|
||||
if(!element) {
|
||||
throw new Error('EnterIsTab Utility cannot be setup without a field element');
|
||||
}
|
||||
|
||||
this._element = element;
|
||||
|
||||
if (this._element.classList.contains(ENTER_IS_TAB_INITIALIZED_CLASS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._element.classList.add(ENTER_IS_TAB_INITIALIZED_CLASS);
|
||||
}
|
||||
|
||||
|
||||
start() {
|
||||
this._element.addEventListener('keydown', (e) => {
|
||||
if(e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
let currentInputFieldId = this._element.id;
|
||||
let inputAreas = document.querySelectorAll(AREA_SELECTOR);
|
||||
let nextInputArea = null;
|
||||
for (let i = 0; i < inputAreas.length; i++) {
|
||||
if(inputAreas[i].id === currentInputFieldId) {
|
||||
nextInputArea = inputAreas[i+1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(nextInputArea) {
|
||||
nextInputArea.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
destroy() {
|
||||
console.log('TBD: Destroy EnterIsTab');
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ import { FormErrorReporter } from './form-error-reporter';
|
||||
import { InteractiveFieldset } from './interactive-fieldset';
|
||||
import { NavigateAwayPrompt } from './navigate-away-prompt';
|
||||
import { CommunicationRecipients } from './communication-recipients';
|
||||
import { EnterIsTab } from './enter-is-tab';
|
||||
|
||||
export const FormUtils = [
|
||||
AutoSubmitButton,
|
||||
@ -17,5 +18,6 @@ export const FormUtils = [
|
||||
InteractiveFieldset,
|
||||
NavigateAwayPrompt,
|
||||
CommunicationRecipients,
|
||||
EnterIsTab,
|
||||
// ReactiveSubmitButton // not used currently
|
||||
];
|
||||
|
||||
@ -209,7 +209,7 @@ commR CommunicationRoute{..} = do
|
||||
((commRes,commWdgt),commEncoding) <- runFormPost . identifyForm FIDCommunication . withButtonForm' universeF . renderAForm FormStandard $ Communication
|
||||
<$> recipientAForm
|
||||
<* aformMessage recipientsListMsg
|
||||
<*> aopt textField (fslI MsgCommSubject) Nothing
|
||||
<*> aopt textField (fslI MsgCommSubject & addAttr "uw-enter-as-tab" "") Nothing
|
||||
<*> (markupOutput <$> areq htmlField (fslI MsgCommBody) Nothing)
|
||||
formResult commRes $ \case
|
||||
(comm, BtnCommunicationSend) -> do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user