question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The select tag example from official React-documentation gives a warning

See original GitHub issue

Implemented “The select Tag” example from https://reactjs.org/docs/forms.html and get this warning:

Warning: The value prop supplied to select must be a scalar value if multiple is false.

I use 16.6.0-pre.61-kotlin-1.3.0: compile ‘org.jetbrains:kotlin-react:16.6.0-pre.61-kotlin-1.3.0’ compile ‘org.jetbrains:kotlin-react-dom:16.6.0-pre.61-kotlin-1.3.0’

import kotlinx.html.InputType
import kotlinx.html.js.*
import org.w3c.dom.HTMLSelectElement
import org.w3c.dom.events.Event
import react.*
import react.dom.*

interface SelectTestState : RState {
    var value: String
}

class SelectTest : RComponent<RProps, SelectTestState>() {
    override fun SelectTestState.init() {
        value = "coconut"
    }

    private fun handleChange(event: Event) {
        val target = event.target as HTMLSelectElement
        setState {
            value = target.value
        }
    }

    private fun handleSubmit(event: Event) {
        println("Your favorite flavor is: ${state.value}")
        event.preventDefault()
    }

    override fun RBuilder.render() {
        form {
            attrs.onSubmitFunction = {
                handleSubmit(it)
            }

            label {
                +"Pick your favorite flavor:"
                select {
                    attrs.value = state.value
                    attrs.onChangeFunction = {
                        handleChange(it)
                    }

                    option {
                        attrs.value = "grapefruit"
                        +"grapefruit"
                    }
                    option {
                        attrs.value = "lime"
                        +"lime"
                    }
                    option {
                        attrs.value = "coconut"
                        +"coconut"
                    }
                    option {
                        attrs.value = "mango"
                        +"mango"
                    }
                }
            }

            input {
                attrs.type = InputType.submit
                attrs.value = "Submit"
            }
        }
    }

}

fun RBuilder.selectTest() = child(SelectTest::class) {}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
weickmannacommented, Mar 28, 2019

Same here. Problems seems to be the setter in RDOMBuilder that always converts the value into a set:

var SELECT.value: String
        get() = ""
        set(value) {
            values = setOf(value)
        }
1reaction
ncallawaycommented, Mar 8, 2019

I’m seeing the same thing with the following select:

select(classes = "form-control") {
    attrs { id = "mySelect"; this.name="mySelect"
        onChange = props.handleChange; onBlur = props.handleBlur; value = "B"
    }
    option { attrs { value = "A" }; +"Option A" }
    option { attrs { value = "B" }; +"Option B" }
    option { attrs { value = "C" }; +"Option C" }
    option { attrs { value = "D" }; +"Option D" }
    option { attrs { value = "E" }; +"Option E" }
}

I discovered this on version: org.jetbrains:kotlin-react:16.6.0-pre.62-kotlin-1.3.0 org.jetbrains:kotlin-react-dom:16.6.0-pre.62-kotlin-1.3.0

It is also reproing for me on the latest versions: org.jetbrains:kotlin-react:16.6.0-pre.69-kotlin-1.3.21 org.jetbrains:kotlin-react-dom:16.6.0-pre.69-kotlin-1.3.21

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forms - React
The select Tag. In HTML, <select> creates a drop-down list. For example, this HTML creates a drop-down list of flavors ...
Read more >
reactjs - HTML Select Input Tag bringing error ... - Stack Overflow
It's basically a warning that encourages you to change your code from doing <option selected> to doing <select defaultValue="theValue"> or ...
Read more >
A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >
How To Customize React Components with Props
In this tutorial, you'll create custom components by passing props to your component. Props are arguments that you provide to a JSX element....
Read more >
Working With ReactJS in WebStorm: Coding Assistance
In JSX tags, the IDE provides coding assistance for React-specific attributes such ... Here's an example from official React documentation: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found