CityWebConsultants / Iris

Modular content management and web application framework built with Node.js and MongoDB
http://irisjs.org
Other
9 stars 7 forks source link

Replace separate singular/multi fields with a single field type where the number can be set in fields settings #238

Open adam-clarey opened 8 years ago

adam-clarey commented 8 years ago

At the minute when adding a field to a schema you have to decide if it will be a single input, or multiple, eg 'Textfield' vs 'Multi text field'.

This is bad UX as as you are not always going to know how many fields will be needed when you add a field to the schema as these things can change. It also means you have to create 2 of every field. An image field was created that i wanted to use to add multiple images to an entity, but it had only been created for a single image so it limited my functionality.

Instead, I believe all fields should be defined as 'multi' in the database. Then when you add a field to a schema, you then choose how many inputs will be available to the end user (same as Drupal fields). You can choose 1,2,3... Unlimited

If '1' is selected then when the entity is fetched the field should not be an array, but a singular value.

For example, i create a textfield 'title' and set its cardinality as 1. When using this field in an entity template, the handlebars tag would be:

{{entity.title}}

However, if the cardinality was > 1, then in the template it would be used as:

{{entity.title[0]}} \\ To get the first item or...

{{#each entity.title}}
  {{this}}
{{\each}}
FilipNest commented 8 years ago

I'm fine with this but only if we retain the ability to also create non array fields. Even if they're hidden in the editor and it's just through hard coding in the schema file that needs to be supported. Being able to create any Mongo schema is one of the best things about the schema system. Particularly if it's used on an API level. We shouldn't lose that.

For the image field you'll have to define a multiple image field type which will need array of object logic in the schema system. We don't currently support that apart from for fieldsets.

The Handlebars part when a field count of 1 is set should be possible to do with hook_entity_view.

adam-clarey commented 8 years ago

Yeah i'm fine with the ability to create singular field types in code