Smart field reference link

Hello,

I’ve set in place a smart field that displays the name of a reccord called display name.
I’ve set it as reference field for the table.
Howerver, when I try to link a reccord from this table and I seash for the smart field it doesn’t appear, I have to search by id.
Do you know how I can enable the search by the smart field display name
Thank you for your help,
Best,
Ilias

Ps : some screenshots to illustrate
departementID
Psearch


Hello @Ilias_El-mhamdi,

Quick question, did you implement a custom search logic? This is needed to search on a smart field.
You can find more details here: Create and manage Smart Fields - Documentation

Let me know if this helps.

(edited to fix the link)

Hello,

No I haven’t and I can’t access your link :confused:

Thank you

I think I’ve found it :slight_smile:
https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields#searching-sorting-and-filtering-on-a-smart-field

Sorry about the wrong link copy-paste :pray:

I’am having some trouble with the search function since my input is a JSON and not a string or number.
Isn’t it possible to search directly against the value of the smart field ?
For info the name field looks like this :
{“FR” : “nameFr”, “EN” : “nameEn”}

I tried something like this but it didn’t work

  fields: [
    {
      field: "displayName",
      type: "String",
      get: (record) => {
        return Object.values(record.name)[0];
      },
      search: async function (query, search) {
        console.log(search, "search");
        var searchCondition = {
          [Op.and]: [{ name: { [Op.like]: `%${search}%` } }],
        };
        await query.where[Op.and][0][Op.or].push(searchCondition);
        return query;
      },
    },
  ],

Unexpected error: operator does not exist: json ~~ unknown

The like operator does not seem to work well here.
Maybe try something like if you field is in JSONB format:

  [Op.or]: [
    { 'name.EN': { [ Op.like]: `%${search}%` } },
    { 'name.FR': { [ Op.like]: `%${search}%` } },
    ],

It works !
Thank you so much !