How to access Default Value of a component

Hi,

How to access (read) Default Value of a component, e.g. of a Text Input field?

I'd expect it to be textInput1.defaultValue, but I can't find anything similar in its state (neither visible nor hidden key-values).

Thanks for help - I basically need to read to be able to use that value in my query.

hi, welcome to the forums

The default value field sets the value property of the component when rendered - so whenever you want to find the value it would be accessed via {{textinput1.value}}
If you wanted to have a value that's accessible outside of this you would need to store it as a variable somewhere, maybe in temporary storage.
forum.json (10.2 KB)

Are you wanting to see the current value of the component? @dcartlidge has you covered.

Are you wanting to see the initial value you supplied, not the current value? Here is the answer for that:

Two ways I am aware of, but they both only work if you supplied the value from another source like {{myTble.currentRow.data.myField}} - if you hardcoded the value like your example then you are out of luck at present.

First, if you used a property from somewhere else, like the {{myTble.currentRow.data.myField}} example form above, then just look at that original source.

Second, if your component is in a form and you supplied the form with an Initial Data property, then the original values will still be in the form's initialData property.

good shout on the initialData, @bradlymathews that would be a neat way to access it too if you're using the field inside a form.

The example app I posted might help explain things @Jan

Thank you both for prompt answers.

In actual case, the Default Value is provided by a query from mongo datasource.

My goal :
Compare Default Value versus textinput1.value (typed by user)

-> for info : if these two are different, then the form Submit button is activated and the background turns yellow (I managed it already)

How would you approach such comparison?
onChange is rather excluded, because in the end it won't refer to default value from databse AFAIK).
Thanks once more!

So the only way to submit the field is to change the default value to something else?
I'm not sure that's what I understood a "default value" to be, but I think I get it now.

Perhaps what you're after is a validation rule on the field that says "must be different to the value from query {{value}}"

So the only way to submit the field is to change the default value to something else?

No, you can submit both : changed and unchanged values. Only that for the changed values the fields' backgrounds will be yellow

(-> so that user knows what was edited and thus differs from the Default Value. Reminder : Default Value is read from database and is a source of truth for the comparison).

It seems that Validation Rules don't work this way, they only indicate undesirable input. Thanks for your help.

So if you don't make any changes then the form can't be submitted - which means the default values won't be used? I think this is the bit that's confusing me.

Highlighting the changes the user has made makes sense and it sounds like you've already solved that part.

I've uploaded another example app, is this more like what you're trying to see?
Try changing values of the text and play with the buttons
forum.json (12.4 KB)

1 Like

Big thanks for the second forum.json, that's what I was looking for.

As I have around 20 fields in my form - do you think there is an alternative to 20xcopy-paste this snippet :
{{(self.value !== default_values_from_database?.value[self.id]) ? 'yellow' : 'white' }}
into "Style>Background" field ?
So far I didn't manage to put it in a reusable query.

Concerning that question :

So if you don't make any changes then the form can't be submitted - which means the default values won't be used?

Submit is possible whenever there is at least one changed input field (then only the changed values will be $set to mongo document).

Hey @Jan! Hopping in here as well to try helping. Are you still blocked anywhere?