Create a Smart Field

A Smart Field is a field that displays processed-on-the-fly data. It can be as simple as concatenating attributes to make them human friendly, or more complex.

A very common example is to have one field for the users' full name instead of having two fields first name and last name.

Lumber
Rails
Express/Sequelize
Express/Mongoose

Inside the /forest/customers.js file, we've declared and implemented the fullname Smart Field.

/forest/customers.js
const Liana = require('forest-express-sequelize');
Liana.collection('customers', {
fields: [{
field: 'fullname',
type: 'String',
get: (customer) => {
return customer.firstname + ' ' + customer.lastname;
}
}]
});

On our Live Demo, the very simple Smart Field fullname is available on the Customer collection. Here's how you implement it:

/lib/forest_liana/collections/customer.rb
class Forest::Customer
include ForestLiana::Collection
collection :Customer
field :fullname, type: 'String' do
"#{object.firstname} #{object.lastname}"
end
end

Inside the /forest/customers.js file, we've declared and implemented the fullname Smart Field.

/forest/customers.js
const Liana = require('forest-express-sequelize');
Liana.collection('customers', {
fields: [{
field: 'fullname',
type: 'String',
get: (customer) => {
return customer.firstname + ' ' + customer.lastname;
}
}]
});

Inside the /forest/customers.js file, we've declared and implemented the fullname Smart Field.

/forest/customers.js
const Liana = require('forest-express-mongoose');
Liana.collection('customers', {
fields: [{
field: 'fullname',
type: 'String',
get: (customer) => {
return customer.firstname + ' ' + customer.lastname;
}
}]
});

Then, after restarting your back office server and refreshing the UI, we will be able to see the new field from your Customer collection.

This Setup Guide step is now done! 🎉