Hi all,
I want to have a custom input field with some automatic connversations.
This works pretty well already.
My problem now is i would like to save the data the template holds and when it gets loaded on a page refresh or first entry on the site it should reappear.
Is there any possibility to do this?
Do i need to use the datatracker for this?
--> Adding New Core Widgets | Node-RED Dashboard 2.0 (flowfuse.com)
<template>
<v-form>
<v-container>
<v-text-field
v-model="pascal"
label="targetPressure"
variant="outlined"
suffix="Pascal"
:rules="[rules.required, rules.rulePascal]"
@input="onPascalInput"
>
</v-text-field>
<v-text-field
v-model="mbar"
label="targetPressure"
variant="outlined"
suffix="mBar"
:rules="[rules.required, rules.pressure]"
@input="onMbarInput"
>
</v-text-field>
<v-text-field
v-model="torr"
label="targetPressure"
variant="outlined"
suffix="Torr"
:rules="[rules.required, rules.pressure]"
@input="onTorrInput"
>
</v-text-field>
</v-container>
</v-form>
</template>
<script>
export default {
data() {
return {
pascal: 0.0,
mbar: 0.0,
torr: 0.0,
rules: {
required: value => !!value || 'Required.',
pressure: value => {
const pattern =
/^(?:(?:0|[1-9]\d{0,2})(?:\.\d+)?|1000(?:\.0+)?|(?:[1-9]\d{0,2}(?:\.\d+)?|0?\.\d+)[eE][-+]?[0-2]?\d{1,2}|(?:1(?:\.\d+)?|0?\.\d+)[eE][-+]?[0-3]\d{0,2}|(?:[1-9]\d?(?:\.\d+)?|0?\.\d+)[eE][0])$/
return pattern.test(value) || 'Invalid format.'
},
rulePascal: value => {
const pattern =
/^(?:(?:0|[1-9]\d{0,4})(?:\.\d+)?|100000(?:\.0+)?|(?:[1-9]\d{0,4}(?:\.\d+)?|0?\.\d+)[eE][-+]?[0-4]?\d{1,2}|(?:[1-9](?:\.\d+)?|0?\.\d+)[eE][0-5]\d{0,2}|(?:[1-9]\d(?:\.\d+)?|0?\.\d+)[eE][0-4])$/
return pattern.test(value) || 'Invalid format.'
},
},
}
},
methods: {
onPascalInput() {
this.updateFromPascal()
this.sendPressure()
},
onMbarInput() {
this.updateFromMbar()
this.sendPressure()
},
onTorrInput() {
this.updateFromTorr()
this.sendPressure()
},
updateFromPascal() {
this.mbar = this.pascal / 100
this.torr = this.pascal / 133.322
},
updateFromMbar() {
this.pascal = this.mbar * 100
this.torr = this.pascal / 133.322
},
updateFromTorr() {
this.pascal = this.torr * 133.322
this.mbar = this.pascal / 100
},
sendPressure(){
const payload = {
topic: 'upload', // Topic for Node-RED
payload: this.pascal, //Content
}
this.send(payload)
}
},
}
</script>
<style>
/* define any styles here - supports raw CSS */
.my-class {
color: red;
}
</style>