Vue 3: Conditional v-if on hmtl attributes - vue.js

I'm trying to conditional rendering an HTML Elements attribute:
EG:
<InputNumber v-model:value="example[index].number"
:min="collector.attr[0] ? collector.attr[0] : 0"
:max="collector.attr[1] ? collector.attr[1] : 0"
:step="0.01"
style="min-width: 120px;"/>
The Problem: the minimum Value of 0 is set (collector.attr[0] = null), but I want eg. that user is able to enter '-100'
The Goal: if the collector.attr[1] is "null" i want to remove the ":min" attribute - resp. only allow this attribute, if there is a minimum value set.
Like so:
<InputNumber
v-if="collector.attr[0]" => then :min="collector.attr[0]"
/>
Thank you very much for your help :)

Probably you can set a minimum value beyond which a user is not expected to input anything. Something like this
<InputNumber :min="collector.attr[0] ? collector.attr[0] : -Number.MAX_VALUE" />
Where Number.MAX_VALUE is maximum allowed float value in java script, so adding - in it makes it negative.

Related

How to use scriptAll to grab all values when the intended value is not text type

I have a page with multiple textboxes and dropdowns with values that I am trying to validate. The values in them will be dynamic in each run.
The HTML looks something like:
<input readonly="readonly" class="form-control valid" data-val="true" data="ABC" aria-invalid="false" xpath="1">
What I want to do is grab the value of "data" for each textbox. I have used scriptAll before in such a case when I was grabbing text by using innerText. However, that won't work with a regular value such as in the HTML above.
I did try one solution that worked:
driver.value(//input[#data])
However, that just grabs the first textbox value, is there a way I can combine scriptAll with driver.value? OR would I be better off doing some JS here?
Thank you in advance!
Yes, refer the docs for scriptAll(): https://github.com/karatelabs/karate/tree/master/karate-core#scriptall
Use whatever JS works to get an attribute value. Haven't tried, but this should work, you get the idea:
* def list = scriptAll('input', "_.getAttribute('data')")

Why do I get this warning: '#Model.property' is not a valid value of attribute 'checked'?

I have several checkboxes that I use for display purposes of 'true' and 'false'. Each one will show me the above warning (I made the warning more generic for the purposes of searching. In reality, it reads #Model.Service_Request_Information.Servicelead, etc, instead of #Model.property)
<input class="custom-control-input" type="checkbox" checked="#item.Servicelead" disabled />
I have read that it is okay to write razor code like this, and the HTML will insert/leave out 'checked' from the attributes depending on the value. It works fantastically for how I want it, and it doesn't prevent my code from compiling. So, any ideas on why I am getting this warning?
Razor will render a boolean attribute if the expression you pass to it evaluates to true. If the expression evaluates to false, the attribute is not rendered at all. That is the Razor feature you are using in your example.
In HTML, valid values for the checked attribute are an empty string or "checked" (Specs) i.e. checked or checked="checked". Visual Studio reports HTML errors as warnings by default, which is what you are seeing. You can either ignore it, turn HTML validation off:
Tools > Options > Text Editor > Html > Validation
Or you can use a ternary expression as demonstrated by other answers:
#(item.Servicelead? "checked" : "")
The checked attribute does not have a value. It should only be set when #item.Servicelead is true.
Use this code instead:
<input class="custom-control-input" type="checkbox" #(item.Servicelead? "checked" : "") disabled />

IONIC 4 Setting Max value that can be inputted

I want to limit the user input in ion-input to just 1000, not the max length of the user input.
How do I achieve that?
You set this "maxlength" property
like, This
<ion-input type="text" maxlength="1000"></ion-input>
You should use a size prop
<ion-input type="text" size="1000"></ion-input>
For anyone who stumble on the same problem with me, I found the solution by using 'max' Validators. You can about all available Validators here:
Angular Validators

Using repeat.for with bound number

Consider sample below:
//edit.html
<input type="number" step="1" value.bind="number" />
<div repeat.for="num of number">${num}</div>
//edit.ts
export class Edit {
number: number = 2;
}
I expect to see 2 divs on first page load and number of divs should change when I change number in input. Instead I get error
Value for 'number' is non-repeatable
I figured it out. If you bind input field to variable, even when variable is number, it will be changed to string when changed by user. In my case, number became string once changed in input field. I used this gist to help me solve this problem:
https://gist.github.com/jdanyow/d9d8dd9df7be2dd2f59077bad3bfb399
It offers custom element and attribute for binding numbers to input fields.

dijit.form.Select won't set value programmatically

I have a dynamic dojo form in which I have a dijit.form.Select whose selected value I have tried to set dynamically through various ways. I get the select widget to load and show the data, but it always ignores my every attempt. I am using dojo 1.7.
var bcntryval = <?= $this->billingContact->countryId;?>;
var countryStore;
function onBillingShow() {
if (countryStore) countryStore.close();
countryStore = new dojo.data.ItemFileReadStore({url: 'CartUtilities.php?action=getcountries'});
dijit.byId("bcntry").setStore(countryStore, bcntryval); // does not set value! but does set the store
dijit.byId("bcntry").attr('value', String(bcntryval)); // doesn't set the value either
dijit.byId("bcntry").set('value', bcntryval)); // nor does this!
}
My markup for the bcntry widget is as follows:
<td><input data-dojo-type="dijit.form.Select" style="width: 10em;" data-dojo-props="sortByLabel:false, maxHeight:'-1'" data-dojo-id="bcntry" id="bcntry" name="bcntry" />
I've invested a fair amount of time on learning dojo. When it works its nice, but the docs leave a lot to be desired!
I am also seeing a similar problem with the dijit.form.FilteringSelect. That also ignores setting the value via javaScript.
I've also tried completely programmatic versions of this code. I have come to the conclusion that setting the value just doesn't work when you're selecting from a store.
This DID work, but its not dynamic.
<div name="scntry" data-dojo-type="dijit.form.Select" data-dojo-props="maxHeight:'-1',sortByLabel:false" value="<?= $this->shippingContact->countryId;?>" >
<?php foreach($this->countryList as $c):?>
<span value="<?= $c->id;?>"><?= $c->name;?></span>
<?php endforeach;?>
</div>
The reason most likely is, that youre trying to set the value of the 'searchAttr'. Instead you would want to set value to the 'identifier'.
Answer is here, check the timeout function on bottom shelf: http://jsfiddle.net/TTkQV/4/
The trick is to set the value as you would set option.value (not option.innerHTML).
normalSelect.set("value", "CA");
filteringSelect.set("value", "AK");
Take a look here, I believe this does what you want in the Dojo way:
Setting the value (selected option) of a dijit.form.Select widget
If not, you can always just use the actual dom selection object and use straight Javascript:
How do I programatically set the value of a select box element using javascript?