Giter Club home page Giter Club logo

Comments (11)

kyoshino avatar kyoshino commented on June 6, 2024 1

For the variable object types, you can add only one field. Actually in your case, you can just use required: false with widget: object instead of variable types:

    fields:
      - label: 'Is it News?'
        name: 'isNews'
        required: false
        widget: object
        fields:
          - label: 'News Description'
            name: 'carousel'
            widget: string
            fields:
              - {label: News Description, name: newsDescription, widget: string, required: false}

The UI will look like:

image image

This cannot be done with Netlify/Decap CMS πŸ˜†

from sveltia-cms.

CarloBu avatar CarloBu commented on June 6, 2024 1

oh, this is much better, thanks!

from sveltia-cms.

kyoshino avatar kyoshino commented on June 6, 2024 1

I think the Decap Relation widget doc mentions the multiple option πŸ™‚ The checkbox UI is only with Sveltia πŸ˜†

I just shipped v0.26.2 to use a checkbox for optional (required: false) objects. I’ll work on conditional fields sometime later.

image

from sveltia-cms.

CarloBu avatar CarloBu commented on June 6, 2024 1

I care a lot about the client's UX, and you make me happy! thanks!

this is better now than I expected!

from sveltia-cms.

kyoshino avatar kyoshino commented on June 6, 2024

I think this is relevant:

Sveltia CMS has already solved this problem by supporting variable types for the Object widget, not only for the List widget. I don’t have a detailed document yet, but you can use the same types option to have conditional fields. Check it out!

from sveltia-cms.

CarloBu avatar CarloBu commented on June 6, 2024

Yes, I'm familiar with this, I'm using this feature already for other collections. You are right, that this is already working from another way. I just thought the boolean + condition field would be a more intuitive solution for this particular case when I need a clear on-off state. this is the solution with the variable types. I just need to inform the client not to generate more than one news field and the problem is solved.

    fields:
      - label: 'Is it News?'
        name: 'isNews'
        required: false
        widget: 'list'
        types:
          - label: 'News Description'
            name: 'carousel'
            widget: string
            fields:
              - {label: News Description, name: newsDescription, widget: string, required: false}
Recording.2024-05-10.095642.mp4

from sveltia-cms.

kyoshino avatar kyoshino commented on June 6, 2024

And yeah, as you said, a checkbox may be more intuitive here. I can change the UI πŸ™‚

from sveltia-cms.

CarloBu avatar CarloBu commented on June 6, 2024

yes, but if it's only not hard to implement for you.

I guess it could be simple ternary operator to the string widget and could look like:

fields:
  - label: Is it News?
    name: isNews
    widget: boolean   <- or checkbox
    default: true
    required: false}
  - label: News Description
    name: newsDescription
    visibleIf: 'isNews'         <- maybe like this, or name it displayCondition?
    widget: string}

from sveltia-cms.

CarloBu avatar CarloBu commented on June 6, 2024

wait, you mentioned checkboxes, are checkboxes possible for relation widget?
image

I went to the sveltia and decapcms issues and found only mention custom tag widget that is not supported at sveltia. I made that the client can build and modify categories list through reference content collection schema, and at current I can only let to select only one item through radio buttons. If it's possible to convert this field to checkboxes to get the array, please give me a hint.
fields:
- {label: Category, name: category, widget: relation, collection: categories, value_field: defaultLocaleVersion, display_fields: [category]}

image

from sveltia-cms.

kyoshino avatar kyoshino commented on June 6, 2024

You can get checkboxes with widget: relation + multiple: true.

from sveltia-cms.

CarloBu avatar CarloBu commented on June 6, 2024

hehe, lol, that's unexpected:
image
it works like a charm!
I double checked now, and I still didn't find about "multiple: true" in the sveltiacms or decap readme.
You need proper documentation about advanced fields. :)
I will collect these cool options that I will find and prepare these for the template, 100% sure very few people know about these powerful options.

from sveltia-cms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.