Giter VIP home page Giter VIP logo

Comments (10)

taflanidi avatar taflanidi commented on September 28, 2024

Hi @krypt-lx
Thanks for your question.

Since I don't have the whole context, I'll assume you've got one of the following scenarios:

  1. Your app is available for a single country

In this case, your phone number values will always contain no country codes, thus the +1 prefix within the field serves only aesthetic/UX purposes.

Hence, for rendering, you must adapt those values and insert the +1 prefix programmatically.

Imagine you have a User object with name and surname fields. You've got to display the full name on the account screen. There's got to be a space between name and surname, so that John Doe becomes John Doe instead of JohnDoe. The values are not prepared for rendering, it is up to you to put that space there.

  1. Your app is available in multiple countries

Therefore, the +1 prefix is information you don't want to lose. You must include it in the value itself.

from input-mask-ios.

krypt-lx avatar krypt-lx commented on September 28, 2024

It isn't answer the question, though. I boiled down the issue I have to simple example.

Basically I have the mask (one which I convert to compatible format in app) and the value from third party via api. It can be any kind of mask for any purpose.
The mask contains some blanks and the value contains only characters for those blanks

So, that it, I need to fill in blanks with given characters and preset it to the user to edit. Nothing more, nothing less.

It isn't hard to manually evaluate the characters in the mask and fill blanks in, but I before I do so I want to know if there maybe a proper solution?

from input-mask-ios.

taflanidi avatar taflanidi commented on September 28, 2024

Ah, the third-party masking patterns :D
My favourites.

A go-to here is a two-step process.
For clarity, let's imagine an example, where you receive a phone number:

{
  "mask": "+1 (###) ### ## ##",
  "value": "1234567890"
}

The 1234567890 value is not for the input-mask library but for the +1 (###) ### ## ## pattern!
So you've got to "zip" it accordingly:

var output = "+1 (###) ### ## ##"
let value = "1234567890"

value.forEach { char in
    output.replace("#", with: String(char), maxReplacements: 1)
}

As you've said earlier,

I need to fill in blanks with given characters
Nothing more, nothing less

—so go ahead and do it.

Next, you apply the input-mask library to the output.

from input-mask-ios.

krypt-lx avatar krypt-lx commented on September 28, 2024

I will add, though, It would be nice if this lib would be able to process its own output (extractedValue). Consider it to be a feature request

from input-mask-ios.

taflanidi avatar taflanidi commented on September 28, 2024

@krypt-lx but you already can.

Inherit, override. Everything's open.

from input-mask-ios.

krypt-lx avatar krypt-lx commented on September 28, 2024

You missing the point: it is not about what I can and what I can't do, the lib can produce output (containing sufficient amount of data) which it can't handle as input. It looks like the lib is incomplete.

from input-mask-ios.

taflanidi avatar taflanidi commented on September 28, 2024

Hey, let's keep this conversation constructive, please.

First of all, describe an expected library behaviour and business features you're trying to achieve. The end goal and the algorithms you'd like to have under the hood.

Second, keep in mind that this library occupies the same shelf as the regular expressions. This is a low-level String-operating utility that has no knowledge about the domain semantics whatsoever—and it must not.

from input-mask-ios.

krypt-lx avatar krypt-lx commented on September 28, 2024

describe an expected library behaviour and business features you're trying to achieve

The task:

The mask contains some blanks and the value contains only characters for those blanks
So, that it, I need to fill in blanks with given characters and preset it to the user to edit. Nothing more, nothing less.

For example, I have mask "123 [000]" and value "345" and I need to construct value "123 345" and present it to the user. The Mask.apply will return "123 45" as the output, so, I can't use it is as.
I expected the lib to have some way to implement required behavior "from the box", specifically because the lib is able to extract values in this format (Mask(format: "123 [000]").apply("123 345").extractedValue will return "345")

I'm aware there are reasons to do it in a different way, but like I already said this is the data format I have. I wrote a simple state machine processing mask format, but I rather avoid having unnecessary complex code in the project.

from input-mask-ios.

taflanidi avatar taflanidi commented on September 28, 2024

@krypt-lx my apologies for the delay.

I'll be able to roll out an update during this week, I guess.

In my head, the use case should be like

let format = "123 [000]"
let input = "234"

let result = Mask(
  format: format, 
  turnOnTheFeatureTemporaryName: true
).apply(toText: input).formattedText

 "123 234"

Please let me know if it works for you.

P.S. If you happen to come up with a catchy name instead of turnOnTheFeatureTemporaryName — let me know as well

from input-mask-ios.

krypt-lx avatar krypt-lx commented on September 28, 2024

fillInBlanksOnly? wildcardsOnly? matchOnlyWildcards?
I guess some combination of "blank" or "wildcard" or how you call those wildcards ([0],{A}, etc) internally and of the fact it limits matching to it?
Also, {123} wildcard, I guess it should match 123 only and return a failure otherwise? Like, "precise" match on all wildcards?
Also, maybe a parameter on .apply? (unless some internal architecture reasons) Because mask probably should work as a way to format the value for text for user to edit and a way to format the user input? But I guess I'm there in a weird spot, it is the inherited code in my case and it do not use MaskedTextInputListener and implements its own UITextFieldDelegate

from input-mask-ios.

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.