Skip to content

Commit

Permalink
Add validation hints on interact fields (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Jun 30, 2022
1 parent b30876b commit 32e78c3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/components/schema/schemaForm/SchemaForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<Michelson v-on="on" :code="value" mutable></Michelson>
</div>
</template>
<template slot="custom-nat" slot-scope="props">
<template slot="custom-bytes" slot-scope="props">
<v-text-field
:key="props.fullKey"
:ref="props.fullKey"
Expand All @@ -37,8 +37,34 @@
dense
outlined
:value="props.value"
:rules="rules.bytes"
:placeholder="props.label">
</v-text-field>
</template>
<template slot="custom-nat" slot-scope="props">
<v-text-field
:ref="props.fullKey"
:label="props.label"
v-on="props.on"
dense
outlined
:value="props.value"
:rules="rules.nat"
:placeholder="props.label">
</v-text-field>
</template>
<template slot="custom-address" slot-scope="props">
<v-text-field
:ref="props.fullKey"
:label="props.label"
v-on="props.on"
dense
outlined
:value="props.value"
:placeholder="props.label"
:rules="rules.address"
>
</v-text-field>
</template>
<template slot="custom-contract" slot-scope="props">
<v-text-field
Expand All @@ -52,6 +78,7 @@
:placeholder="props.label"
:hint="schema.properties[props.modelKey] && schema.properties[props.modelKey].tag ? `\'Fill\' button finds the newest contract with this contract type. If contract's absent nothing is set.` : ``"
persistent-hint
:rules="rules.contract"
>
<template v-slot:append-outer v-if="schema.properties[props.modelKey] && schema.properties[props.modelKey].tag">
<v-btn text small @click="$emit('getRandomContract', props)" class="text--secondary">
Expand Down Expand Up @@ -91,7 +118,8 @@
import SchemaOptionalSettings from "./SchemaOptionalSettings";
import SchemaFormExecutionActions from "./SchemaFormExecutionActions";
import Michelson from "@/components/Michelson";
import { isKT1Address, isTzAddress } from "@/utils/tz.js";
export default {
name: "SchemaForm",
components: {
Expand Down Expand Up @@ -139,6 +167,24 @@ name: "SchemaForm",
return {
selectedFillType: 'empty',
model: {},
rules: {
contract:[
v => v.length == 36 || 'The length of the contract address is 36 characters',
v => isKT1Address(v) || 'In this field you should write the address of the contract. It begins with KT.'
],
nat: [
v => /^\d+$/.test(v) || 'Only digits are allowed',
v => v.length > 2 && v[0] !== '0' || "Nat can't starts from zero"

This comment has been minimized.

Copy link
@djangobits
],
bytes: [
v => v.length % 2 == 0 || "The length of the byte string must be even",
v => /^[0-9a-fA-F]*$/.test(v) || 'Only 0-9 and a-f are allowed',
],
address: [
v => v.length == 36 || 'The length of the address is 36 characters',
v => isTzAddress(v) || isKT1Address(v) || 'In this field you should write the address'
]
}
};
},
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export function applyStyles(node) {
if (node.prim === "nat" || node.prim === "mutez") {
node["x-display"] = "custom-nat"
}
if (node.prim === "bytes") {
node["x-display"] = "custom-bytes";
}
if (node.prim === "address") {
node["x-display"] = "custom-address";
}
}
if (node.properties) {
for (var prop in node.properties) {
Expand Down

0 comments on commit 32e78c3

Please sign in to comment.