Giter Site home page Giter Site logo

Comments (3)

gerjanvangeest avatar gerjanvangeest commented on June 2, 2024 1

The same behaviour can be found in other input fields. The serializedValue() is used to update the serializedValue every time the value changes, so it is part of our core value behaviour. Changing this is will be hard, since it will influence a lot of code.

What you could do is to set the serializedValue only once in firstUpdated(), and not on every paint.

from lion.

Madses avatar Madses commented on June 2, 2024

I've figured out a workaround until fixed. Seems to work without any issues for me.
Given that it consistently defaults to ".serializedValue," we can ensure that this value stays current whenever a modification occurs. While not ideal, it serves the purpose for now.

 static properties = {
    count: { type: Number },
    currentValue : {type: String}
  };

  constructor() {
    super();
    this.count = 0;
    this.currentValue = 'diplodocus';
  }
  
render() {
    return html` <lion-form
      name="dinosaurs"
      .serializedValue=${{ favoriteDinosaur: this.currentValue }}
    >
      <form>
        <lion-radio-group
          name="favoriteDinosaur"
          label="What is your favourite dinosaur ${this.count}?"
          @model-value-changed=${(e) => {
            this.currentValue = e.target.modelValue;
            this.count += 1;
          }}
        >
          <lion-radio
            label="Allosaurus"
            .choiceValue=${'allosaurus'}
          ></lion-radio>

          <lion-radio
            label="Brontosaurus"
            .choiceValue=${'brontosaurus'}
          ></lion-radio>

          <lion-radio
            label="Diplodocus"
            .choiceValue=${'diplodocus'}
          ></lion-radio>
        </lion-radio-group>
      </form>
    </lion-form>`;

from lion.

Madses avatar Madses commented on June 2, 2024

I believe I've found the cause of this issue.
in ChoiceGroupMixin.js there is the following function.

      /**
       * @param {ChoiceInputHost} el
       * @param {string} val
       */
      const checkCondition = (el, val) => el.serializedValue.value === val;

      if (this.__isInitialSerializedValue) {
        this.registrationComplete.then(() => {
          this.__isInitialSerializedValue = false;
          this._setCheckedElements(value, checkCondition);
          this.requestUpdate('serializedValue');
        });
      } else {
        this._setCheckedElements(value, checkCondition);
        this.requestUpdate('serializedValue');
      }
    }

Here's whats happening:

  1. If statement succesfully runs, and sets the checked value to value.
  2. Right after this function runs again, but since this.__isInitialSerializedValue was set to false it then goes to the else statement. and sets the checked value once again, which is fine, but (i believe) unnecessary.
  3. Every time we try to select a different radio option set serializedValue(value) gets invoked for some reason. The value briefly changes to the desired one, but then it immediately changes back to the initial serializedValue.

I am not sure what the desired result was of this specific part :

        this._setCheckedElements(value, checkCondition);
        this.requestUpdate('serializedValue');
      } 

So i'm not confident in proposing a solution yet. Although i did try a few things that seem to work and passed the tests.

One is simply removing this._setCheckedElements(value, checkCondition); in the else block. Another was instead of passing value to this._setCheckedElements inside the else block, we could instead pass this.modelValue as an argument. e.g. this._setCheckedElements(this.modelValue, checkCondition);

from lion.

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.