Editbox placeholder(textview) moves down or up when we click outside editbox

Editbox placeholder(textview) moves down or up when we click outside editbox
0
#1

I am having one problem with editbox. when I click on it, it textfield comes in the center but when I off from editbox, placeholder(textfield move to down)

0 Likes

#2

I think it’s the expected behavior.
Or not? :thinking:

1 Like

NEW USERS READ THIS! New User Guidance
#3

It should be the same, if the editbox has the focus or not. The gif looks weird, but I didn’t test it on my own yet.

1 Like

#4

yeah in some case it is expected but see how bad it looks in my case I mean, there should be some method which makes it happen, do you know how to stop it i have looked into editbox source code also but I couldn’t find out any method which moves this placeholder, I have changed placeholder anchor point in source code but then it moves a lot than in this GIF so any help please…

I have tried textfield too but then I am having another problem with it … this is the GIF of textfield. first problem… cursor shows up in the middle even though i have set vertical and horizontal alignment and when we change text to password or password to text it moves and looks wired cause password styles character is small and actual text character is bigger than that

0 Likes

#5

The behavior in your first post is correct, where the input method overlay disappears when the text input field loses focus, and that’s described in such documentation as what is available here:

https://developer.android.com/training/keyboard-input/visibility

You may be able to control it via the manifest file or java code, but I’m not entirely certain.

What isn’t correct is the cursor appearing in the wrong position within the text field. How are you creating that edit box in code?

0 Likes

#6

about first post editbox, I have looked into code but I am not good with NDK so i get lost every time I am trying to follow code with debugger, it should have some listener which moves textfield of editbox when keyboard show and disappear. i am posting this post every possible place but no respnse…

about second one : “textfile” – this is my code for textfield

it has size posiotion problem also when I turn on and off passwordStyle

I have given name editbox2 but it is textfiel sorry about that

//--> editbox2
editbox2 = cocos2d::ui::TextField::create("Password","fonts/arial.ttf",30);
editbox2->setContentSize(Size(100,18));
editbox2->setAnchorPoint(Point::ANCHOR_MIDDLE_LEFT);
editbox2->setPosition(Vec2(170.0f,150.0f));
editbox2->setFontSize(10);
editbox2->setTextHorizontalAlignment(cocos2d::TextHAlignment::LEFT);
editbox2->setTextVerticalAlignment(cocos2d::TextVAlignment::CENTER);
editbox2->setMaxLengthEnabled(true);
editbox2->setMaxLength(15);
editbox2->setVisible(false);
editbox2->setString("");
editbox2->setCursorEnabled(true);
editbox2->setCursorPosition(0);
editbox2->setCursorChar('|');
this->addChild(editbox2);

editbox2->addEventListener([&](Ref *pSender, ui::TextField::EventType type){

    auto * textField = dynamic_cast<ui::TextField*>(pSender);

    switch (type) {
        case ui::TextField::EventType::ATTACH_WITH_IME: {

            log("i am in 1\n");

        }
            break;

        case ui::TextField::EventType::DETACH_WITH_IME: {

            log("i am in 2\n");

            if (textField->getString() == "") {


                textField->setString("");

            }

            break;

        case ui::TextField::EventType::INSERT_TEXT:
        {   


            log("i am in 3\n");
            int index = textField->getStringLength() - 3;

            if(index < 0){}
            hiddenPassword[index] = textField->getString()[index];


            if (isPassword) {

              
                char tempstring[20] = {0};

                for (int i = 0 ; i <= index    ; i++) {

                    tempstring[i] = '*';

                }

                textField->setString(tempstring);


            }

        }
            break;

        case ui::TextField::EventType::DELETE_BACKWARD:

        {

            log("i am in 4\n");

            int index = textField->getStringLength();

            log("delet hidden index : %d\n",index-3);

            hiddenPassword[index-2] = 0;

            log("hidden password : %s\n",hiddenPassword);


        }
            break;

    }


});
0 Likes

#7

I’m not entirely sure what you’re trying to achieve within the event listeners, but is there any reason you didn’t call setPasswordEnabled(true) on the text field. Like this:

editbox2->setPasswordEnabled(true);
0 Likes

#8

yes… if i call setPasswordEnabled(true)… i am getting problem shown in below GIF… watch FULL GIF you will get it

when I setPasswordEnabled(false) text field change it position and revers too

that’s why i have implemented my own pasword method … so now i have only one problem and that’s that cursor shows up in the middle even though i have set anchor point left

below GIF IS Before i have set my own password method inlistner now after setting up password method in listener i am having only one problem that is about cursor

0 Likes

#9

Oh I get what you mean now, so you use it to show or hide the password when the user clicks on the eye symbol.

Can you try something? Call this method every time you want to change the visibility of the text, and see if it helps. Make sure you disable all the code you have in the event handlers you pasted above so they don’t mess with it.

void ShowPassword(bool state)
{
    auto currentText = editbox2->getString();
    editbox2->setPasswordEnabled(state);
    editbox2->setString("");
    editbox2->setString(currentText);
}

Let me know if it works.

0 Likes

#10

okay let try… I will let you know… I am sorry i am having some android studio problem so i will let you know as soon as i run it :slight_smile:

0 Likes

#11

thanks… it’s working, Now no need to implement own password logic, but still i have that cursor problem it shows off to the middle of text field until we start typing even though we have set Anchor point left

0 Likes

#12

You may need to log an issue on the tracker regarding the cursor problem:

Have you tried to run the cpp-tests app to see if that issue occurs there too? It has the UI test section in there.

0 Likes

#13

i have created issues there

someone told me about that test thing and i have tried that and not working can you send me link or something so I can check that it is same that you are telling me and that person sent me. By the way do you have discord or something like that I am in one cocos2dx discord server but it is like dead

0 Likes

#14

Find your Cocos2dx installation, and go into the \tests\cpp-tests\ folder, and load up whichever project you want to compile. The Android Studio project is in

\tests\cpp-tests\proj.android

The Windows Visual Studio project is in:

\tests\cpp-tests\proj.win32

As for Discord, I didn’t even know there was a Discord server for Cocos2d-x, but for me personally it’s not something I would use to discuss issues, as they’re better left on this forum.

0 Likes

#15

okay, I am going to try this test thing…thanks again, yeah there is discord server but not officially :slight_smile: by the one more problem is there. when you press backspace it will remove one by one character and that is expected but when it deletes all character and one more time you hit backspace button and it gives an error and stops working

E/SpannableStringBuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

I found workaround it but I thought I just let you know if you find the solution about editbox or cursor please let me know

0 Likes

#16

I wouldn’t know what would be causing that, since I neither use the component nor know the code associated with it. Perhaps someone else here can help with that specific issue.

0 Likes

#17

ohh okay, in editbox everything work fine just one issues and that is that moving thing :slight_smile: i hope it fix soon

0 Likes

#18

Someone will take a look at the Github issue.

Also, if you have multiple questions, please post one per topic. You asked a few questions here and it makes it hard to know what you have solved and what isn’t.

Also, no need to go to other topics saying people aren’t helping you. It also clutters those topics.

0 Likes

#19

okay…I won’t go to other topics and I will open a new topic for each problem…

in here, I have asked two question, none of this is solved

  1. about editbox : editbox placeholder change its position when it gets in focus and when it loses focus, how do we have normal editbox so it looks good rather than like in below GIF

  1. about Textfield : text field shows cursor in the middle when it gets focus even though we have set Anchor point left, right or any. it moves it right postion(according to anchor point) when you start typing.

you can see it in below GIF

And about GitHub, It’s been four days and no one even replies that we are working on it or not even anyone watched my Issues or participated and some other issues that have been posted after mine they are being replied, so it’s kind of wired, so I hope they are working on it or at least they have noticed the editbox and textfield issues.

0 Likes

#20

We can ask @drelaptop to take a look. I know he is working on tasks and also there is a holiday starting in a few days.

@drelaptop there are a few .gifs in this thread that show the issue and here is the GitHub issue

0 Likes