Wix Code filter not working - velo

Im new to wix code. I created a simple database with a title field and some other fields as a test.
I created a text edit box so i can type in a search text, and a grid object so i can see the results.
I connect the grid to the data base and all the fields such as image, description etc.
Then i run the preview mode without typing anything, the grid shows all the table elements.
When i type into the search, even if i type something that is in the table, the grid is blank, seems the filter doesnt work??
Anybody knows why???
here is my code attached to the page
import wixData from "wix-data"
$w.onReady(function () {
});
export function iAddress_keyPress(event, $w) {
filter($w('#iAddress').value); // iAddress is the name of the input text box
}
function filter(title) {
$w('#dataset1').setFilter(wixData.filter().contains('Title',title));
}

Simple. This is problem:
contains('Title',title)
Title - it's "name" of the column. You should use "field name" from collection, it's displayed when you press "manage properties" on some column - it's actually id.
In your case, "title" is correct field name (as it's default)
Your example will work with this:
contains('title',title)

Related

Create a non-editable field in Strapi

I have a project that sells products.
A product can have a price and optional: new_price. I would like to be able to sort them by price/new_price combined, meaning that I would need an additional entry in the DB like "final_price". I got an idea to create a non-editable field "new_price" in Content-Type Builder/schema.json and then update that with the final price for the product on "beforeCreate" in the lifecycles.js. However, I am not sure Strapi allows that, as I haven't been able to find a resource pointing in the documentation that it can. If there is a hacky way to do it, please advise. I am open to all kinds of other suggestions on how to do this Business logic as well.
Thank you in advance.
There is a way in strapi to make the field non editable on UI. You can go to Content-type-builder-> Your component-> Configure the view. And click on the text field. You can just make editable field as false.
I see two options:
(a) Add the field and forget about it being non-editable. You can calculate the final_price on insertion of an entry in your collection with Lifecycle hooks: https://docs.strapi.io/developer-docs/latest/development/backend-customization/models.html#lifecycle-hooks.
(b) Don't add a new field, but override the controller to return an additional field: https://docs.strapi.io/developer-docs/latest/development/backend-customization/controllers.html#extending-core-controllers.
Ok, so I found a "hacky" way to do this. I don't like it, as it is not that beautiful and sophisticated, but it does the job.
In product schema.json I added a
"final_price": {
"type": "decimal"
}
In lifecycles.js, I created a new function that will calculate my final price and write it in "final_price" attribute:
module.exports = {
beforeCreate(event) {
priceCalc(event);
},
beforeUpdate(event) {
priceCalc(event);
},
};
const priceCalc = (event) => {
const { data } = event.params;
data.final_price = data.new_price ? data.new_price : data.price;
};
In the admin panel, in Content-Type Builder in Product, I clicked "Configure the view" and deleted the Final Price field from Displayed Fields section. This made the field hidden, lol.
Now I am sorting all products with sort: ['final_price:asc']
That is it.Hope it helps anyone!

v-combobox, strange behaviour

I am having a weird problem with my v-combobox that is hard to explain but I will try my best.
When i start typing in the combobox the "list" gets filtered and if i click one of the items in the dropdown menu everything is fine.
The problem hapens if i click an item and then add another letter and directly press the send button in my form, the new charachters in my combo box is not passed to my axios request. If i instead change to another field all the information in my combobox is passed to the axios.post request.
But the weirdest part is that if i put:
console.log(this.shortname)
The output contains all characters in the combobox but not in the axios.post request.
Below is my code.
// TEMPLATE
<v-combobox v-model="shortname" color="forms" :items="shortnames" autocomplete="off"></v-combobox>
// SCRIPT
sendForm(){
console.log(this.shortname)
axios.post('/endpoint, {
shortname: this.shortname
})
.then((response) => {})
}
So in the sendForm() function if i type "Richa" in the combobox and click the "Richard" listitem the
console.log(this.shortname) // outputs "Richard" and so will axios request
But if i type "Richa" and click the "Richard" listitem and then ADD "sdf" (Richardsdf)
the
console.log(this.shortname) // outputs "Richardsdf" but axios request is still "Richard"
However if i change fields after I add "sdf" axios.post will have "Richardsdf"
Im using vuetify version 2.4.2 and same behaviour on chrome and safari
My question is if there is a way to be able to get all added info into the combobox without having to change input fields?
// Best regards.
Found the solution.
I added id="targetInput" and #update:search-input="updateTargetInput" and removed the v-model to combobox
<v-combobox id="targetInput" #update:search-input="updateTargetInput" :items="shortnames" outlined :rules="shortnameRules"></v-combobox>
and in the methods i added
methods: {
updateTargetInput(currentValue){
this.shortnameone = currentValue
console.log(this.shortnameone)
},
}
Credits go to PradeepNooney
https://github.com/vuetifyjs/vuetify/issues/4679#issuecomment-682456398

detail row grid with popup editor

I read posts and seen examples but I am still strugling with setting up hierarchy grid with one popup editor form for both master/detail record(s).
I would like to setup a simple grid with html row detail
where grid data source is a nested json:
persons = [
{ name:"john", surname:"smith" },
{ name:"jane", surname:"doe",
contact: [
{ type:"email", value:"jane.doe#domain.com" },
{ type:"phone", value:"012345678" }
]
}
]
Top grid level displays name and surname where detail template shows
simple list of contacts (if any).
Grid needs to be editable through a popup editor where both data (master and detail) can be edited. Name and surname are binded to one form where contacts are displayed in a simple grid binded to a separate "contact" form located above it.
<form input fields for name and surname>
<form input fields for contacts, binded to a contacts table>
<contacts table>
<save><update><cancel>
Problems:
in detail row initialization I only get top level data (no contacts) so I am unable to render detail row with list of contacts
how to handle contacts part in popup editor? how to bind data?
Thank you for all your input, Peter
Found out that editing misbehaved due to missing "record id". Once I provided unique id I am getting expected results.
Duplicated question here.

kendo grid, change text of custom button

Does anyone know how to change text of custom button in Kendo UI, when it is defined like:
c.Command(command =>
{command.Custom("custom").Click("Action").Text("Text");
})
in order to after click on that button, the text could change.
thanks in advance for answers.
Using your sample code,
The "custom" parameter is useless/ignored by the parser (leaving nothing means "custom")
the Click("") parameter is the name of a Javascript function that will be executed upon a click
The Text("") parameter is the default text (when Razor is executed/page loads)
c.Command(command =>{command.Custom("custom").Click("Action").Text("Text");})
you'd need a function like:
function Action(e) {
e.target[0].innerText = "Some new text for the button"
}

Add an "Add New..." option to a Kendo DropDownList

I'm using a Kendo DropDownListFor which populates from a DB table. I want to add an option at the end that says "Add New..." which takes the user to a Create view for that DB table. Is there a way to do this (preferably in the MVC Helper, not in javascript).
Not possible without JavaScript. If using JavaScript you need to use the change event and see if the value is equal to that last item in the list then navigate the page. Something like this:
function onChangeOfDDl(e){
if(...) { //you condition
window.location.href = "/editRecord/" + this.value()
// this.value() will give you the value for the selected item or the text if no underlying value exists
}
}

Resources