Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Change Object Type

Questions related to using nuBuilder Forte.
Post Reply
mvdm
Posts: 17
Joined: Fri Mar 18, 2022 5:03 pm
Has thanked: 2 times

Change Object Type

Unread post by mvdm »

Maybe a silly question, but is it possible to change the Object Type via JS?
Depending if it is a Edit Record or Add Record, I would like to have an object in a form either be a Display object or Select object. This would be really neat if it works because you can already store the Display and Select SQL in the same object.

This is related to a depended dropdown data entry form, so I want to be able to select a value from a previous table, to filter the value in the next table. In Edit Record I would like for this to be a Display object just to show the value previously selected, and in Add Record I want it to have a Select object so that I can filter the options in the consequent Select object (dependent dropdown)

Many thanks in advance!
kev1n
nuBuilder Team
Posts: 4299
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Change Object Type

Unread post by kev1n »

Hi,

To turn an object (e.g. Select) into a disabled input field, use this JS:

Code: Select all

function changeObjectTypeToInput(i) {

    let el = $('#' + i);
    let l = el.cssNumber('left');
    let t = el.cssNumber('top');

    el.replaceWith($('<input />').attr({
        type: 'text',
        id: el.attr('id'),
        name: el.attr('name'),
        class: el.attr('class'),
        value: el.val()
    }));

    el = $('#' + i);

    el.css({
        top: t,
        left: l,
        position: 'absolute'
    });
    nuDisable(el.attr('id'));

}

changeObjectTypeToInput('your_object_id') // <-- Replace your_object_id with your object id.
mvdm
Posts: 17
Joined: Fri Mar 18, 2022 5:03 pm
Has thanked: 2 times

Re: Change Object Type

Unread post by mvdm »

Hi Kev1n,

Thank you for your quick response, yes that worked.
I added nuRefreshDisplayObject(i); at the end of changeObjectTypeToInput(i) and it also runs the specified Display SQL.
Post Reply