Problem with InputText

UI Components for React
Post Reply
kaho29
Posts: 18
Joined: 18 Aug 2017, 10:57

18 Aug 2017, 11:03

Hello,

first I want to say, that I really enjoy Primefaces and also the new PrimeReact. Really great work you're doing here.

I have a slight problem with the InputText component that I can't get around. Problem is as follows:

I want to dynamically change classnames on the InputText when there is an error. Everything works fine (setting the variable classnames and passing it to the component) but the InputText is not re-rendered correctly. The effects of the added css classes don't show up directly, but only, when the state of the InputText changes (for example when you enter text into the field).

Is this a bug or am I missing something?

User avatar
sudheer
PrimeFaces Core Developer
Posts: 4345
Joined: 16 Oct 2011, 19:19
Location: Singapore

18 Aug 2017, 17:27

AFAIK, it should be reflected without state change as well. Can you create an example with primereact quickstart example
Author,Speaker
https://twitter.com/sudheerjonna
Github: https://github.com/sudheerj
Website http://sudheerjonna.com/

___________________
Sudheer Jonna

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

21 Aug 2017, 14:08

Could you please share code so we can review?

kaho29
Posts: 18
Joined: 18 Aug 2017, 10:57

21 Aug 2017, 16:16

I found the problem myself in the meantime.

It is inside this block in the InputText.js:

Code: Select all

{
    key: 'shouldComponentUpdate',
    value: function shouldComponentUpdate(nextProps, nextState) {
        if (this.state.filled === nextState.filled && !this.inputProps.value) {
            return false;
        }
        return true;
    }
}
Because in my case I wanted to change the className on an input with empty value to realise a required-fields-check, the component was not re-rendered because this.state.filled was equal to nextState.filled AND the value was still empty / unset.

I worked around this by overwriting the component and changing this block slightly. It now looks like this:

Code: Select all

{
    key: 'shouldComponentUpdate',
    value: function shouldComponentUpdate(nextProps, nextState) {
        if (this.state.filled === nextState.filled && this.props.className === nextProps.className && !this.inputProps.value) {
            return false;
        }
        return true;
    }
}
Just added && this.props.className === nextProps.className to the if-clause and now it works for me.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

21 Aug 2017, 18:58

Thank you, being reviewed by our team.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

21 Aug 2017, 19:11

Please try it with PrimeReact 1.0.0-beta 5 or 6 version.

kaho29
Posts: 18
Joined: 18 Aug 2017, 10:57

22 Aug 2017, 09:36

Checked with beta 6 and it works now. No wonder, as I noticed the "shouldComponentUpdate" is now removed from the InputText.

Thank you for the quick responses :)

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

22 Aug 2017, 16:01

Glad to hear, thanks for the update!

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 10 guests