statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Select Field integer default value -> value displayed instead of text #1816

Closed krausste closed 6 years ago

krausste commented 6 years ago

Expected behaviour

The text of the default option is shown instead of the value. And the value is saved without enclosing quotes (which might be the cause of the issue somehow - after choosing another option the int value is saved without quotes).

Actual behaviour

The default value is shown instead of the text that belongs to the default's value option.

Steps to reproduce

  1. Add a Select field to any of your fieldsets
  2. Add a default value of type integer to this field
  3. Add an option with this value and add a text to it

Server Details

Statamic Version: 2.8.7

jackmcdade commented 6 years ago

This is working as intended now in 2.9.x. Please reopen if you find a condition otherwise!

krausste commented 6 years ago

Hi Jack, unfortunately this is still not working for us in 2.9.6. I will add some screenshots. Can you please reopen the ticket? Thank you! select field int default value - fieldset config 1-3 select field int default value - fieldset config 2-3 select field int default value - fieldset config 3-3 select field int default value - contentstore new select field int default value - contentstore labels

jackmcdade commented 6 years ago

Alright, trying again with his exact setup. 🙏

krausste commented 6 years ago

great! thank you :)

jackmcdade commented 6 years ago

Confirmed. I must have been testing it wrong. Will get it fixed up for 2.9.7. 👍

jackmcdade commented 6 years ago

Found it. The default is probably stored as a string, and therefore not matching the int value in the options object. With a little type coercion, we're back in business.

If you need this fixed immediately, you can pop open the fieldset yaml file directly and remove any string quotes:

options:
  1: First
  2: Second
  3: Third
default: '2' # change to 2
krausste commented 6 years ago

Alright, thank you!

krausste commented 6 years ago

Hi there, this is still not fixed in 2.9.8. default int values are still stored with quotes inside the yaml config file.

jackmcdade commented 6 years ago

Correct, we couldn't change that, but the loading side checks if the string is numeric and type casts it back to an int so the display shows correctly. You said it's not fixed because it's not saved as an int, but does it work as expected?

krausste commented 6 years ago

Nope, also not working as expected. Only when removing the quotes manually its working.

jackmcdade commented 6 years ago

Can you post the fieldset config for the field you're using?

krausste commented 6 years ago

sure. see field_9 and quote set inside the bard field

title: Long Form Post
hide: true
sections:
  main:
    display: Main
    fields:
      title:
        type: text
        display: Title
        localizable: true
      section_1:
        type: section
        display: Section 1
      template:
        type: hidden
        default: blog/long_form
      long_form:
        type: bard
        display: Long Form Content
        sets:
          image:
            display: Image
            fields:
              photo:
                display: Photo
                type: assets
                container: main
                folder: img
                max_files: 1
              caption:
                type: text
              size:
                type: radio
                default: Normal
                options:
                  Normal: Normal
                  Oversized: Oversized
          quote:
            display: Pull Quote
            fields:
              quote:
                display: The Quote
                type: markdown
              cite:
                type: text
                display: Cite
              select:
                type: select
                display: Select
                options:
                  10: Label 1
                  20: Label 2
                  30: Label 3
                default: "10"
          grid:
            display: Grid
            fields:
              grid:
                type: grid
                display: Grid
                fields:
                  text:
                    type: text
                    display: Text
                  text_2:
                    type: text
                    display: Text 2
                  togggle:
                    type: toggle
                    display: Togggle
                mode: table
        spellcheck: true
        allow_source: true
      section_2:
        type: section
        display: Section 2
      text:
        type: text
        display: Text
      tags:
        type: taxonomy
        taxonomy: tags
      field_9:
        options:
          1: label 1
          2: label 2
        type: select
        display: Field 9
        default: "1"
taxonomies: true