Dataset create a new element using other fields

Hi,
is it possible to combine two existing dataset (collection) fields into a new field that will be the blend of the 2 existing field.

Example:

Fields
FirstName = Lacasse
LastName = Pierre
New field
CompletName = Pierre Lacasse

Thank you for your advice

Pierre Lacasse

Hi

What do you need to achieve exactly? Just display the blend ?

Jerome,
The blend would be First Name + Last Name ( In this exemple it wiould be “Pierre Lacasse”

I actually was successful merging the two fields using the form. I created an inputbox to link to a dataset field
.
.
let nomComplet2 = $w(“#input6”).value + " " + $w(“#input7”).value
$w(“#input9”).value = nomComplet2;

    $w("#dynamicDataset").save(); 

I can see that my Input9 field displays the combined value which is in my case Pierre Lacasse .

but when I do the dynamicDataset saves, it doesn’t go into the new field I had created in my database.

Any idea?

Pierre Lacasse

Can you manage to have a button to validate the creation,?
If so, just tested with a button, connected to the dataset, with “submit” option, and a new record is created in collection with the input value (in my case, I just merged to text fields value).

Jerome,
how do you merge to text fields value?

The $w(" #dynamicDataset ").save(); is the same as a Submit button. I proved it earlier

Pierre

This worked (new item created in dataset, with merged value of the 2 text fields).
I could not get the item to record based on the third, merged field value, though.
Will that do?

 $w("#dataset1").onReady( () => {
    $w("#dataset1").new()
      .then( ( ) => {
        $w("#dataset1").setFieldValue("email", $w("#text12").text + $w("#text13").text );
        $w("#dataset1").save();
      } )
      .catch( (err) => {
 let errMsg = err;
      } );
  } );

Jérome,
where do you put this code? form and it create a new field on the form?

Have you ever used the backend to create a calculated field… Using this, I was able to add a new column in my Collection which merge two columns. The only problem, I want to use this field to search in my Collection and then post the results using a repeater. I cannot yet access this new “calculated field” for searching.

Any experience with calculated fields?

Pierre

Pierre,

I put this code in the code of the page.
Sorry no xp with calc fields in the backend. why do you dynamically create a column and not just add it beforehand?

Jérome,
thank you again for your help. It worked the way you proposed it.

On an other related subject, have you ever created 2 different search buttons on the same dataset?
I tried this but it doesn’t work when I had the second search button.
The first search works perfectly

// search member name in dataset column “nomComplet”
export function input1_keyPress(event, $w) {
filter($w(‘#input1’).value);
}
function filter(title) {
$w(‘#dataset1’).setFilter( wixData.filter().contains(‘nomComplet’, title));
}
// search member name in dataset column “villeActuelle”
export function input2_keyPress_1(event, $w) {
filter($w(‘#input2’).value);
}
function filter2(title) {
$w(‘#dataset1’).setFilter( wixData.filter().contains(‘villeActuelle’, title));
}

I guess it does not work because you call filter() instead of filter2() in the second function?

Jérome,
finally this code works
Thank you!

Pierre Lacasse

let debounceTimer;
export function input2_keyPress_1(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);

debounceTimer = undefined;
}
debounceTimer = setTimeout (() => {
filter($w(‘#input2’).value);
}, 200);
}
console.log (filter)
let lastFilterTitle;
function filter(title) {
if (lastFilterTitle !== title) {
$w(‘#dataset1’).setFilter( wixData.filter().contains(‘villeActuelle’,title));
lastFilterTitle = title;

}
}
export function input1_keyPress(event, $w) {
if (debounceTimer) {1// clearTimeout(debounceTimer);

debounceTimer = undefined;
}
debounceTimer = setTimeout (() => {
filter1($w(‘#input1’).value);
}, 200);
}
console.log (filter)
let lastFilterTitle2;
function filter1(title) {
if (lastFilterTitle !== title) {
$w(‘#dataset1’).setFilter( wixData.filter().contains(‘nomComplet’,title));
lastFilterTitle2 = title;

}}