Skip to content

Commit

Permalink
fixed errors in terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
SneakyTurtlle committed Oct 25, 2023
1 parent 068b109 commit 6ba7643
Showing 1 changed file with 54 additions and 74 deletions.
128 changes: 54 additions & 74 deletions vue/dynamicforms/src/components/form/inputs/base-composable.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import TableColumn from "../../table/definitions/column";
import {DfTable} from "../../table/namespace";
import TableRows from "../../table/definitions/rows";
import FilteredActions from "../../actions/filtered-actions";
import TableFilterRow from "../../table/definitions/filterrow";
import FormField from "../definitions/field";
import _ from "lodash";
import _ from 'lodash';
import { computed } from 'vue';

import {reactive, computed} from 'vue'
import FilteredActions from '../../actions/filtered-actions';
import FormField from '../definitions/field';

export interface BaseProps {

Expand All @@ -21,73 +17,57 @@ export interface BaseEmits {
(e: 'update:modelValue', value: any): any
}


export function useInputBase(props: BaseProps, emit: BaseEmits){

const isNumber = computed(() => {
return props.field.renderParams.inputType === 'number'
})

function isValidNumber(num: any) {
const notValidValues: any[] = [undefined, Number.NaN];
if (!props.field.allowNull) {
notValidValues.push(null);
notValidValues.push('');
}
return !_.includes(notValidValues, num) && !Number.isNaN(num) &&
!_.includes(String(num), ',') && !_.endsWith(String(num), ',');
export function useInputBase(props: BaseProps, emit: BaseEmits) {
const isNumber = computed(() => props.field.renderParams.inputType === 'number');
function isValidNumber(num: any) {
const notValidValues: any[] = [undefined, Number.NaN];
if (!props.field.allowNull) {
notValidValues.push(null);
notValidValues.push('');
}
return !_.includes(notValidValues, num) && !Number.isNaN(num) &&
!_.includes(String(num), ',') && !_.endsWith(String(num), ',');
}

Check failure on line 30 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Expected indentation of 2 spaces but found 4

Check failure on line 30 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / build

Expected indentation of 2 spaces but found 4

Check failure on line 30 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Expected indentation of 2 spaces but found 4

const value = computed({
get(): any {
return props.modelValue;
},
set(newValue: any) {
// TODO this is to be moved to input.vue. It has nothing to do here.
if (isNumber.value && isValidNumber(newValue)) {
emit('update:modelValue', newValue ? Number(newValue) : undefined);
return;
}
emit('update:modelValue', newValue);
},

})

const errorsList = computed(() => {
return props.errors || []
})

const errorsDisplayCount = computed(() => {
return errorsList.value.length
})

const label = computed(() => {
return props.showLabelOrHelpText ? props.field.label : undefined
})

const helpText = computed(() => {
return props.showLabelOrHelpText ? props.field.helpText : undefined
})

const baseBinds = computed(() => {
// this is potentially vuetify-specific
return {
label: label.value,
'error-messages': errorsList.value,
'error-count': errorsDisplayCount.value + 10, // +10 so that it can show "rules" error messages
messages: helpText.value ? [helpText.value] : undefined,
}
})

return{
value,
errorsList,
errorsDisplayCount,
label,
helpText,
baseBinds,
isNumber,
isValidNumber
const value = computed({
get(): any {
return props.modelValue;
},
set(newValue: any) {
// TODO this is to be moved to input.vue. It has nothing to do here.
if (isNumber.value && isValidNumber(newValue)) {
emit('update:modelValue', newValue ? Number(newValue) : undefined);
return;
}
emit('update:modelValue', newValue);
},
});

const errorsList = computed(() => props.errors || []);

const errorsDisplayCount = computed(() => errorsList.value.length);

const label = computed(() => props.showLabelOrHelpText ? props.field.label : undefined);

Check failure on line 50 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Arrow function used ambiguously with a conditional expression

Check failure on line 50 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / build

Arrow function used ambiguously with a conditional expression

Check failure on line 50 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Arrow function used ambiguously with a conditional expression

const helpText = computed(() => props.showLabelOrHelpText ? props.field.helpText : undefined);

Check failure on line 52 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Arrow function used ambiguously with a conditional expression

Check failure on line 52 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / build

Arrow function used ambiguously with a conditional expression

Check failure on line 52 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Arrow function used ambiguously with a conditional expression

const baseBinds = computed(() => {

Check failure on line 54 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`

Check failure on line 54 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`

Check failure on line 54 in vue/dynamicforms/src/components/form/inputs/base-composable.ts

View workflow job for this annotation

GitHub Actions / Code coverage

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`
// this is potentially vuetify-specific
return {
label: label.value,
'error-messages': errorsList.value,
'error-count': errorsDisplayCount.value + 10, // +10 so that it can show "rules" error messages
messages: helpText.value ? [helpText.value] : undefined,
};

});
return {
value,
errorsList,
errorsDisplayCount,
label,
helpText,
baseBinds,
isNumber,
isValidNumber,
};
}

0 comments on commit 6ba7643

Please sign in to comment.