14

Set auto completion on Ninox editor

Hello everyone, 

I was fed up with always having to close the code editor to fetch the name of a field or table, so I set up the Ninox code editor to have an auto-completion function :

press ctrl+space on the editor to display the completion list.

The list contain all Ninox functions, data base table and fields for each table and global user functions :

Ninox uses CodeMirror to edit its code. This editor is very complete and I didn't have too much trouble adding autocomplete. It is a classic CodeMirror add-on and there are many examples of how to do it on the web. The CodeMirror documentation also helped me a lot.
I think it is easy to improve the syntax highlighting.  I will try it later.

 

Because this code is long, I create GitHub repository with all code I did and published in this forum. You can download it here : https://github.com/JacquesTur/Ninext

To add the code on your application, you can copy the content of the completion.html file on GitHub and put it in on one formula :

html("
put the copy of code here
");

Or use the following code in your formula:

html(http("GET", "https://raw.githubusercontent.com/JacquesTur/Ninext/main/completion.html").result)

In this last solution, your application will have directly the last modifications of the code in real time, the improvement... but also the new bugs 😅.    

71 replies

null
    • UweG
    • 2 yrs ago
    • Reported - view

    Bonjour Jaques.
    Excellent travail.
    Ça facilite le scripting.
    J'admire toujours ton travail.
    Salutations
    ---
    Hello Jaques.
    Great work.
    Makes scripting easier.
    I always admire your work.
    Greetings

    Uwe

    • UweG
    • 2 yrs ago
    • Reported - view

    I did a little promotion for your forum entry in the german forum:
    https://forum.ninox.de/t/q6hbpkh

    -----
    For all those who do a lot of scripting in Ninox, the following entry in the English Ninox forum is recommended:
    https://forum.ninox.com/t/g9hbpzh/set-auto-completion-on-ninox-editor
    and the corresponding GitHub page:
    https://github.com/JacquesTur/Ninext

    Jaques had already programmed such a possibility for Ninox before the introduction of dynamic selection fields.
    His work is always a highlight from my personal point of view.
    --

    Greetings
    UweG

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      UweG Thank you very much for your words Uwe 🙏

    • Alan_Cooke.1
    • 2 yrs ago
    • Reported - view

    Hi there Jacques,

    Could you explain this in a little more detail please.  I am trying your second option by simply placing in a formula in a form.  That does not seem right so I am not surprised it is not working.  If you could advise where exactly I should place the "GET" example I would be grateful.  Does it need to be added as a formula on every 'page' one wants this option?

    • Ninox developper
    • Jacques_TUR
    • 2 yrs ago
    • Reported - view

    Yes, just put the code in a formula and have it show up on the screen at least once. It is not necessary to put the formula on all the tables, just one.

    I think I know what the problem is. I was in the process of making some changes and I think I mistakenly published a non-functional version on GitHub. 
    Could you try now to see if it works?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Jacques TUR  here is a little more detail

       

      • Alan_Cooke.1
      • 2 yrs ago
      • Reported - view

      Jacques TUR This is amazing!!!  What I did was put the formula in a 'Settings' table that never gets used.  As a matter of interest I assume this will work in the Console as well.  I never use it myself.  Could it be used in Global Settings?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Alan Cooke The formula must be displayed at least once for it to work. If the table is never used, it will not work the next time the database is opened.

      Once the module is initialized, it works everywhere there is a code editor (table, form, column, report...) except in the console because it is not really a code editor. 

      Everywhere else Ninox uses CodeMirror as a code editor. It's a very complete component that has a lot of possibilities (look at the demo using the comboBox "Other demo..." here : https://codemirror.net/#)

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Alan Cooke For example we could add :

    • Sean
    • 2 yrs ago
    • Reported - view

    This is awesome Jacques TUR . It's incredible that Ninox has not implemented some of the features that you have listed, especially search and replace. Do you know if Ninox is going to implement an add-on ability like import or require? That would be so much nicer than putting the code in a Formula field in an active table.

    • planoxpro
    • 2 yrs ago
    • Reported - view

    Great job Jacques, thanks for that!


    Small note: "this.ID" is used in lines 1, 140 and 174 of badges.html. I had to change that to "this._id".

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      planox.pro Thank you for this comment. Why did you change this?
      It seems to me that in the end it comes down to the same thing, because Ninox ends up translating this._id as this.ID.

      • planoxpro
      • 2 yrs ago
      • Reported - view

      Jacques TUR I suspect "_id" is the internal variable that is substituted differently. With the language setting "German" it does not become "ID" but "Nr". If you write "ID" directly, Ninox gives an error message.

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      planox.pro Yes, of course you are right, the translation is different in different countries. So using this._id works for all countries.
      Thanks, I'll change that in the online code.

    • Ninox developper
    • Jacques_TUR
    • 2 yrs ago
    • Reported - view

    Good evening to all, 

    Following today's webinar, I have modified the structure of the code to make it more easily improved.
    At the same time, I added configuration parameters and a function call after the code initialization.

    The variable "configLoadModules" is used to define which modules should be loaded. Afterwards it will allow to parameterize these modules, like for example the colour of the bagdes.

    The "afterLoadModules" function is called as soon as the code is initialized. It allows to display a message or to close the current window. In the example above, the window is automatically closed if you are not in database administration mode. 

    var configLoadModules := {
            completion: true,
            badges: true,
            evalJS: true
        };
    function afterLoadModules() do
        if not isAdminMode() then closeRecord() end
    end;
    html(http("GET", "https://raw.githubusercontent.com/JacquesTur/Ninext/main/loadModules.html").result)

    It is this code that must now be put in the initialization formula. The previous code I shared (.html file) is still available, but it will no longer be maintained or improved. 

    note: this new code introduces a new possibility: from the JavaScript, call a Ninox function located in a formula. This will allow events to be handled between HTML/JavaScript without going through the Rest API. More functions will come soon...

      • Sean
      • 2 yrs ago
      • Reported - view
      Jacques TUR said:
      This will allow events to be handled between HTML/JavaScript without going through the Rest API.

      Would this allow modifications to data, e.g., add or modify records via HTML/Javascript in a local database?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Sean This allows a Ninox function to be called. In this function you can do everything that can be done in a function like the Ok button function, including changing, adding or updating data, deleting records.

      You can also pass it parameters to get data from JavaScrip. 
       

      but beware: I remind you that all this is experimental and that it is really not 
      not recommended to use it in commercial applications with clients 

    • Fred
    • 2 yrs ago
    • Reported - view

    Hi Jacques -

    I'm using the Mac app and I can't seem to get it to work. I'm copying the code into a html() function and when I press ctrl + space nothing happens. Do you know if it supposed to work in the Mac app?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Fred Yes, now it works fine on the web and on mac, but just before I had a problem. I just fixed it. Can you try it now?

    • Fred
    • 2 yrs ago
    • Reported - view

    What a fast response! I've copied the "new" completion.html into a formula field and still nothing happens. In another formula field when I type "select r" then press ctrl+space. I would think a submenu pops up, but nothing.

    Am I doing it right?

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Fred It's not easy from a distance. Can you send me your example application to this address jacques.tur@neuf.fr?

      • Peter_Romao.1
      • 2 yrs ago
      • Reported - view

      Jacques TUR I'm on a Mac App and also tried to use it. Ctrl+Space pops up the choose keyboard MacOS system dialog to choose a keyboard layout.

      • Ninox developper
      • Jacques_TUR
      • 2 yrs ago
      • Reported - view

      Peter Romão 

      It seems that your system configuration is in conflict with auto-completion. I'll see if I can make the keystroke set that activates auto completion configurable.

      In the meantime, can you modify your system configuration to make it work?

      • Peter_Romao.1
      • 2 yrs ago
      • Reported - view

      Jacques TUR Worked like a charm. Good thinking! The configurable shortcut is a great idea.

    • simon
    • 2 yrs ago
    • Reported - view

    Jacques – thank you so much for sharing your work! I've just had a chance to install it and it works brilliantly. I particularly like that Global formulae show in red! Brilliant work!

Content aside

  • 14 Likes
  • 2 yrs agoLast active
  • 71Replies
  • 1556Views
  • 18 Following