Focus in form-options with create() API seems not working - my solution

Focus in form-options with create() API seems not working - my solution

con7con7 Posts: 1Questions: 0Answers: 0
edited August 2016 in Free community support

Hi,

I just want to post it my solution for the problem I have encountered.
Perhaps it will be helpfull for others. If you find better solution - please
correct me.

I want to have create form with no focus performed. This is because
I want mobile users to see the entire form without displaying android keyboard.
For mobile view - if any text input element is focused - then the android
keyboard is displayed instantly and user is not able to get familiar
with the entire form. So for mobile devices - none of elements should get
focus.

The problem is that focus property seems not working. When I start form
like this:

editor.focus=null;  
editor.title('Create package');
editor.buttons('Save');
editor.create();

nothing happens - the first element is focused. I thought that maybe I should
do like this:

editor.focus(null); 
editor.title('Create package');
editor.buttons('Save');
editor.create();

But that seems to not working too.

So for these who have a problem like me - please define focus behaviour
at the beginning:

editor = new $.fn.dataTable.Editor( {
        ajax: {
            create: {
                type: 'POST',
                url:  'db.php?operation=add'
            },
            edit: {
                type: 'POST',
                url:  'db.php?operation=update&id=_id_'
            },
            remove: {
                type: 'POST',
                url:  'db.php?operation=delete&id=_id_'
            }
        },
        table: "#example",
formOptions: {
                main: {
                        focus: null,
                }
            },


Furthermore, I make something like this so the focus is switched
off only for the mobile devices

        formOptions: {
                            main: {
                                    focus: IsMobileAndTablet() ? null : 0,
                            }
                },

Conrad

Replies

  • allanallan Posts: 63,813Questions: 1Answers: 10,516 Site admin

    Hi Conrad,

    Your final solution looks like a really nice way of doing it - thanks for sharing this with us!

    Allan

This discussion has been closed.