Add vn-input-account tag and logic
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Pau 2022-09-27 12:12:25 +02:00
parent 9d7e12d861
commit d30065f90a
3 changed files with 73 additions and 2 deletions

View File

@ -53,3 +53,4 @@ import './datalist';
import './contextmenu';
import './rating';
import './smart-table';
import './input-account';

View File

@ -0,0 +1,70 @@
import ngModule from '../../module';
import Field from '../field';
export default class inputAccount extends Field {
constructor($element, $scope, $compile) {
super($element, $scope, $compile);
this.buildInput('text');
this.element.addEventListener('click', e => {
console.log(this.element);
console.log(e);
let targetElement = e.target;
console.log(targetElement);
let currentValue = targetElement.value;
let arrayValue = currentValue.split('');
console.log(arrayValue);
let pointer = 0;
targetElement.addEventListener('keyup', e => {
this.$.$applyAsync(async() =>
pointer = await insertFunction(e, targetElement, currentValue, arrayValue, pointer));
$scope.digest();
});
});
async function insertFunction(e, targetElement, currentValue, arrayValue, pointer) {
if (e.key == 'Backspace' || e.key == 'ArrowLeft') {
pointer != 0 ? pointer-- : pointer;
return pointer;
} else if (e.key == 'ArrowRight') {
pointer != 10 ? pointer++ : pointer = 0;
return pointer;
}
console.log(e);
currentValue = targetElement.value;
arrayValue = currentValue.split('');
console.log(arrayValue);
let keyToInsert = e.key;
console.log(`Pointer => ${pointer}`);
console.log(`InputKey => ${keyToInsert}`);
arrayValue[pointer] = keyToInsert;
targetElement.value = arrayValue.join('');
if (pointer < 10) pointer++;
if (arrayValue.length > 10) {
console.log(`Demasiado largo --> ${arrayValue.length}`);
arrayValue = arrayValue.slice(0, 10);
console.log(`Se ha eliminado el ultimo elemento añadido --> ${arrayValue}`);
targetElement.value = arrayValue.join('');
}
console.log(targetElement.value);
return pointer;
}
}
}
ngModule.vnComponent('vnInputAccount', {
controller: inputAccount
});

View File

@ -56,12 +56,12 @@
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
<vn-input-account
vn-one
label="Account"
ng-model="$ctrl.supplier.account"
rule>
</vn-textfield>
</vn-input-account>
<vn-autocomplete vn-one
ng-model="$ctrl.supplier.sageTaxTypeFk"
data="sageTaxTypes"