Announcement

Collapse
No announcement yet.

Input formatting and receive input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Input formatting and receive input

    Hi
    Please see attached GIF to see code in action!

    Basically you put number in input (either by typing o pasting) and it automatically gets comma " , " for decimal or " ' " apostrophe for million. It all works great.

    The thing is, I cannot prevent users from typing characters (e.g. a, b, c..etc).

    Of course I can enable Input mask and set it to: #########. That would limit users to type only numbers up to 999'000,000...which is great but....at the same time, whatever code is in On Char is ignored and what you see in GIF no longer works.

    So, can I have both? input formatting (input mask) and code recognised in On Char?

    Thanks!

    Here is code within On Char


    Code:
    local NumeroSinPuntuacion
    local CantFinal
    
    local SearchCliente = Input.GetText("inp_Cantidad");
    
    local BuscaMillon = String.Find(SearchCliente, "'", 1, false);
    
    
    if BuscaMillon ~= -1 then --si es que encuentra el signo de millon entonces se sobreentiende que tambien existe el signo de coma decimal, asi que ambos seran reemplazados por "" es decir ambos signos seran removidos
    
    NumeroSinPuntuacion = String.Replace( String.Replace(SearchCliente, "'", "", false) ,",", "", false );
    
    else --si no encuentra el signo de millon, entonces buscará el signo de coma decimal, si es que lo encuentra, lo remueve
    
    local BuscaComa = String.Find(SearchCliente, ",", 1, false);
    
    if BuscaComa ~= -1 then
    
    NumeroSinPuntuacion = String.Replace(SearchCliente, ",", "", false);
    
    else --si tampoco encuentra coma decimal, entonces no hace nada
    
    NumeroSinPuntuacion = SearchCliente
    
    end
    end
    
    
    
    local saberLength = String.Length(NumeroSinPuntuacion);
    local e_Char = saberLength
    
    if e_Char > 3 and e_Char < 7 then
    
    local LosNumerosAntesDeComa = String.Left(NumeroSinPuntuacion, e_Char-3);
    local LosNumerosDespuesComa = String.Right(NumeroSinPuntuacion, 3);
    
    CantFinal = LosNumerosAntesDeComa..","..LosNumerosDespuesComa
    Input.SetText("inp_Cantidad", CantFinal);
    
    local saberLength2 = String.Length(CantFinal);
    
    Input.SetSelection("inp_Cantidad", saberLength2 + 1, saberLength2 + 1); -- con esto sitúo el cursor al final del input para que los números que tipeen se añadan al final, de lo contrario los numeros que se tipeen aparecerian al inicio del input
    
    elseif e_Char >= 7 then
    local LosNumerosAntesDeComaMILLON = String.Left(NumeroSinPuntuacion, e_Char-6);
    local LosNumerosDespuesComaMILES = String.Right(NumeroSinPuntuacion, 3);
    local LosNumerosMedios = String.Mid(NumeroSinPuntuacion, (e_Char-6) + 1, 3);
    
    CantFinal = LosNumerosAntesDeComaMILLON.."'"..LosNumerosMedios ..","..LosNumerosDespuesComaMILES
    Input.SetText("inp_Cantidad", CantFinal);
    
    local saberLength2 = String.Length(CantFinal);
    
    Input.SetSelection("inp_Cantidad", saberLength2 + 1, saberLength2 + 1); -- con esto sitúo el cursor al final del input para que los números que tipeen se añadan al final, de lo contrario los numeros que se tipeen aparecerian al inicio del input
    
    elseif e_Char <= 3 then
    
    CantFinal = NumeroSinPuntuacion
    
    end
    
    
    local cualSelecc = XamlListBox.GetSelectedItem("SampleLB");
    
    if cualSelecc ~= -1 then
    
    XamlListBox.SetUpdate("SampleLB", false);
    
    local elTextData = XamlListBox.GetItemData("SampleLB", cualSelecc);
    local elTextDataEX = XamlListBox.GetItemDataEx("SampleLB", cualSelecc);
    
    local tbl_Info = AE.StringDelimitedToTable(elTextData, ";");
    
    local s = string.format(strXamlSample1,elTextDataEX, CantFinal, tbl_Info[3], tbl_Info[4])
    XamlListBox.SetItemText("SampleLB", cualSelecc, s)
    XamlListBox.SetItemData("SampleLB", cualSelecc, tbl_Info[1]..";"..SearchCliente..";"..tbl_Info[3]..";"..tbl_Info[4]..";"..tbl_Info[5]);
    
    XamlListBox.SetUpdate("SampleLB", true);
    
    end



    Image input-typing in David Ramirez's images album

  • #2
    A quick search found :

    Code:
    --Function: Filter Key Press for On Key Event
    
    function FilterKeyPress(InputObject, e_Key, sAllowed)
    sOrig = Input.GetText(InputObject)
    sFilter = String.TrimLeft(sOrig, sAllowed)
    sFilteredLeft = String.TrimLeft(sOrig, sFilter)
    sFilteredRight = String.TrimRight(sFilteredLeft, sFilter)
    Input.SetText(InputObject, sFilteredRight)
    
    Input.SetSelection(InputObject, String.Length(Input.GetText(InputObject)) + 1, String.Length(Input.GetText(InputObject)))
    Input.SetSelection(InputObject, -1, 1)
    end
    --Example calls (Should be in the On Key Event)
    -- allow only numerics
    FilterKeyPress(this, e_Key, "1234567890")
    
    -- allow only Capital Letters
    FilterKeyPress(this, e_Key, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
    --allow All Letters
    FilterKeyPress(this, e_Key, "AaBb***dEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxY yZz")
    Another way:

    Code:
    function bNumbersOnly(nText)
    -- does the string consist only of valid numeric characters?
    if string.match(nText, "^[%d]+$") ~= nil then
    return true;
    else
    
    return false;
    end
    end

    Comment


    • #3
      Here's another example using window subclassing in MemoryEx, one of the original examples of the plugin.
      It requires the MemoryEx plugin

      It will only allow digits and a single point. It will also replace a comma for a point.
      Attached Files
      Bas Groothedde
      Imagine Programming :: Blog

      AMS8 Plugins
      IMXLH Compiler

      Comment


      • #4
        Thanks Colc and Bas for your help. It has been some difficult weeks.I will try your examples and let you know.

        Comment

        Working...
        X