Giter Site home page Giter Site logo

Comments (13)

cfortes avatar cfortes commented on June 25, 2024 1

@melloware oh yes this version I also tested and it is working fine!

from primefaces.

melloware avatar melloware commented on June 25, 2024

In PrimeFacess 6.1 it used the dead and deprecated jquery.mask.js plugin. It was upgraded to the modern InputMask plugin with this one: #6062

The newer InputMask is kept up to date, had way more features and bugfixes as you can see that PR closed 4 previous issues.

But let me revisit this to see what can be done as you have seen from this issue which is why we strip the optional "slotChar" #6469

from primefaces.

melloware avatar melloware commented on June 25, 2024

Cc @tuerker who originally requested the fix that you mentioned above.

from primefaces.

cfortes avatar cfortes commented on June 25, 2024

Awesome, thank you! I can see many scenarios where removing the slotChar from the incomplete masked input value would be the right move and why it was implemented this way. But as I mentioned there are some cases where keeping the optional slotChar had some usefulness. Thats why I suggested that it should be interesting to have an option for both solutions.

from primefaces.

melloware avatar melloware commented on June 25, 2024

@cfortes thanks for the report. Also do you need a workaround for 13.x to get this working the way it was? I can provide one if you don't have one you are already using?

from primefaces.

cfortes avatar cfortes commented on June 25, 2024

Yes I'd like a workaround! I've been trying to find one but nothing really works

from primefaces.

melloware avatar melloware commented on June 25, 2024

Ok I will post here tomorrow how you can make it work.

from primefaces.

melloware avatar melloware commented on June 25, 2024

@cfortes give this a try just unzip and run mvn clean jetty:run and go to http://localhost:8080/
pf-11958.zip

basically i override the renderer to only strip out the slotChar IF you are using an "optional" mask.

public class SlotCharInputMaskRenderer extends InputMaskRenderer {

    @Override
    public void decode(FacesContext context, UIComponent component) {
        InputMask inputMask = (InputMask) component;

        if (!shouldDecode(inputMask)) {
            return;
        }

        decodeBehaviors(context, inputMask);

        String clientId = inputMask.getClientId(context);
        String submittedValue = context.getExternalContext().getRequestParameterMap().get(clientId);

        if (submittedValue != null) {
            // strip mask characters in case of optional values
            String mask = inputMask.getMask();
            if (mask.contains("[") || mask.contains("]")) {
                submittedValue = submittedValue.replace(inputMask.getSlotChar(), Constants.EMPTY_STRING);
            }
            
            if (inputMask.isValidateMask() && !LangUtils.isEmpty(submittedValue) && LangUtils.isNotBlank(mask)) {
                Pattern pattern = translateMaskIntoRegex(context, mask);
                if (!pattern.matcher(submittedValue).matches()) {
                    submittedValue = Constants.EMPTY_STRING;
                }
            }

            inputMask.setSubmittedValue(submittedValue);
        }
    }
    
}

from primefaces.

cfortes avatar cfortes commented on June 25, 2024

@melloware thank you it worked!
I only have one question, is it ok to force autoClear = false when there is optional mask? #11959
I'm asking because isn't there a possibility of the user input an invalid value and it won't be cleared when the mask is optional?

from primefaces.

melloware avatar melloware commented on June 25, 2024

So in the renderer we do this...

// autoclear must be false when using optional mask
            boolean autoClear = inputMask.isAutoClear();
            if (mask.contains("[") || mask.contains("]")) {
                autoClear = false;
            }

Basically if you are using optional mask it automatically sets AutoClear="false".

Do you think that is still OK?

from primefaces.

cfortes avatar cfortes commented on June 25, 2024

@melloware I've done the following test:

<p:inputMask 
    value="#{exampleController.value}"
    mask="(99) 9999[9]-9999"
    autoClear="true">
</p:inputMask>
  • the mask "(99) 9999[9]-9999" is used for phone numbers, and its value has an optional extra digit
  • I've inputed "000" an incomplete and invalid value. it has been validated correctly, it has been recognized as invalid and sent null to the server
  • but it kept the incorrect value on the screen

from primefaces.

melloware avatar melloware commented on June 25, 2024

did you try it with validateMask="false"? The optionals make server side prevention tough. In 6.1 we were not defending the security of someone just doing a FORM POST and sending you an invalid value for a mask so we prevent invalid submissions.

from primefaces.

melloware avatar melloware commented on June 25, 2024

Also I just tested and mine is not keeping the incorrect version on the screen?

pf-11958-2.zip

from primefaces.

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.