I am developing insert form I have a like this input fields and I want to do dynamicly enable and disable to required attribute in my input field . All field names , types , requirements etc returns from json file …
forexample;
<input dmx-show="columnDisplayType != 'INTEGER'" dmx-bind:type="'number'" class="form-control" dmx-bind:id="'decimal1'+$index" dmx-bind:name="columnName" dmx-bind:placeholder="columnName" >
BUT I NEED TO DO ;
<input dmx-show="columnDisplayType != 'INTEGER'" dmx-bind:type="'number'" class="form-control" dmx-bind:id="'integer'+$index" dmx-bind:name="columnName" dmx-bind:placeholder="columnName" required="" data-msg-required="test validation message">
I want to add this attribute to dynamic
can anyone guide me @patrick , @George , @Teodor
Teodor
February 21, 2019, 9:59am
2
Hello Serhat,
The disabled attribute is available in dynamic attributes, when you select your input.
Hello @Teodor ,
but I want to enable it dynamicly ..
if json file return "validation= active" then dynamicly add this attribute and validation message
required="" data-msg-required="test validation message"
t11
February 21, 2019, 10:13am
4
What it migh work is to save the ‘validation=active’ value into a cookie. Then on loading the json to update the cookie value. Apply the ‘Disabled’ value when the cookie value = active
Teodor
February 21, 2019, 10:13am
5
Ah you are referring to toggling the required attribute?
Try: dmx-bind:required="validation == 'active'"
Try setting a variable and using it as the show condition. You can then toggle the variable’s value from pretty much any dynamic action which will be reflected in the visibility of the input field
Teodor
February 21, 2019, 10:21am
7
Why using a variable when you can use dynamic attributes directly?
dmx-bind:required="condition == 'somethig'"
dmx-bind:disabled="condition2 == 'somethig elese'"
dmx-bind:readonly="condition3 == 123"
1 Like
because somefield doesnt require this attribute .. I am trying now your solutions ..
Teodor
February 21, 2019, 10:24am
9
Well you can also try then:
dmx-bind:data-msg-required=“condition == 'abc' ? 'message here' : ''”
1 Like
Added
<input dmx-show="columnDisplayType != 'CODELOOKUP'" dmx-bind:type="text" class="form-control" dmx-bind:id="'input1'+$index" dmx-bind:name="columnName" dmx-bind:placeholder="columnName" dmx-bind:required="isColumnNullable == 'false'" dmx-bind:data-msg-required="isColumnNullable == 'false' ? 'message here' : ''">
Result
<input class="form-control" is="dmx-input" value="" id="input10" name="Extra" placeholder="Extra" data-msg-required="" style="">
there isnt “required” attribute
Teodor
February 21, 2019, 10:36am
13
Then your condition is not met …
this is returned condition from json
Teodor
February 21, 2019, 10:40am
15
Then use:
dmx-bind:required="isColumnNullable == false" dmx-bind:data-msg-required="isColumnNullable == false ? 'message here' : ''"
as the ‘false’ returned by the json is not a string and your condition expression is wrong.
Thank you sooo much @Teodor
working !!!
1 Like