Welcome to the nuBuilder Forums!

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

Readonly + Select Field Combine

Questions related to using nuBuilder Forte.
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Readonly + Select Field Combine

Unread post by Olikun »

Hello,

in Germany it is a public holiday (Easter). Nobody has to work and I have time to work on my project.


I have a new question


I have prepared a nice picture again.

I have a select field with the choice:

Priginal
BBQ
Chili

I want the fields for BBQ and Chilli to be read-only when "Original" is selected.

If the field "BBQ" is selected, the other fields must be write-protected.

Is that possible?
Can the fields change live?
or does the form have to be updated?


Image
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Readonly + Select Field Combine

Unread post by kev1n »

Hi,

Add an onchange event to your select "Sorte" and call typeChanged()
onchange.png
In your form's Custom Code:

Code: Select all

var arrTypes = {
    Original: ['2', '3'],  // <---- replace 2, 3 with your object IDs
    BBQ: ['4', '5'], // <---- replace 4, 5 with your object IDs
    Chili: ['6', '7']  // <---- replace 6, 7 with your object IDs
}

function enableType(Type, enable) {
    for (f in arrTypes[Type]) {
        nuEnable(arrTypes[Type][f], enable);
    }
}

function enableTypes(o, b, c) {
    enableType('Original', o);
    enableType('BBQ', b);
    enableType('Chili', c);
}

function typeChanged() {

    var type = $("#1 option:selected").text();  // <---- replace 1 with your select's object ID.
    switch (type) {
        case "Original":
            enableTypes(true, false, false);
            break;
        case "BBQ":
            enableTypes(false, true, false);
            break;
        case "Chili":
            enableTypes(false, false, true);
    }

}
Replace 2,3,4, etc. with your Object IDs.
sc.png
You do not have the required permissions to view the files attached to this post.
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Readonly + Select Field Combine

Unread post by Olikun »

Thank you
it works right away

but

If I edit the form it works.

I save and close the form and open it again.
Then the fields are active again.

The fields are only read only again when the select field is used.


can we somehow change that?

We can also make the fields hidden if it works better?
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Readonly + Select Field Combine

Unread post by kev1n »

I was already expecting that question ;)

Add this to your form's Custom Code:

Code: Select all

if (nuFormType == 'edit') {
    typeChanged();
}
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Readonly + Select Field Combine

Unread post by Olikun »

where exactly do i add it?

I wrote it like this in the form's custom code

Unfortunately it does not work :/

Code: Select all

if (nuFormType == 'edit') {
    typeChanged();
}

var arrTypes = {
    Original: ['1W14', '1W17'],  // <---- replace 2, 3 with your object IDs
    BBQ: ['1W15', '1W18'], // <---- replace 4, 5 with your object IDs
    Chili: ['1W16', '1W19']  // <---- replace 6, 7 with your object IDs
}

function enableType(Type, enable) {
    for (f in arrTypes[Type]) {
        nuEnable(arrTypes[Type][f], enable);
    }
}

function enableTypes(o, b, c) {
    enableType('Original', o);
    enableType('BBQ', b);
    enableType('Chili', c);
}

function typeChanged() {

    var type = $("#1W11 option:selected").text();  // <---- replace 1 with your select's object ID.
    switch (type) {
        case "Original":
            enableTypes(true, false, false);
            break;
        case "BBQ":
            enableTypes(false, true, false);
            break;
        case "Chili":
            enableTypes(false, false, true);
    }

}
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Readonly + Select Field Combine

Unread post by kev1n »

Sorry, it has to be like that:

Code: Select all

if (nuFormType() == 'edit') {
    typeChanged();
}
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Readonly + Select Field Combine

Unread post by Olikun »

Thank you
it works


But one more problem

I have to explain


I have two forms, but it's only one database.

Department 1 = form number 1

Department 2 = form number 2


The varieties Original / BBQ / Chili are in form number 1 a "Select Field"
The employee can edit it

In form number 2 it is not a select field but a text field (readonly). Only the value is displayed.
The employee cannot edit it.


I took a nice picture again :D

Image
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Readonly + Select Field Combine

Unread post by kev1n »

Replace

Code: Select all

$("#1W11 option:selected").text()
With

Code: Select all

$("#sorte_text_field_ID").val()
to make it work with a Text Input
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Readonly + Select Field Combine

Unread post by Olikun »

perfect again


Thank you

it works great
Olikun
Posts: 68
Joined: Tue Mar 09, 2021 6:45 pm

Re: Readonly + Select Field Combine

Unread post by Olikun »

New problem has occurred

I have 2 halves on the form with different Readonly + Select Field Combine

Image


I tried to adapt the code, but it doesn't work
I duplicated the code and adjusted the field IDs

Code: Select all

// WAGEN 1


if (nuFormType() == 'edit') {
    typeChanged();
}

var arrTypes = {
    Original: ['1W14'],  // <---- replace 2, 3 with your object IDs
    BBQ: ['1W15'], // <---- replace 4, 5 with your object IDs
    Chili: ['1W16']  // <---- replace 6, 7 with your object IDs
}

function enableType(Type, enable) {
    for (f in arrTypes[Type]) {
        nuEnable(arrTypes[Type][f], enable);
    }
}

function enableTypes(o, b, c) {
    enableType('Original', o);
    enableType('BBQ', b);
    enableType('Chili', c);
}

function typeChanged() {

    var type = $("#1W11 option:selected").text();  // <---- replace 1 with your select's object ID.
    switch (type) {
        case "Original":
            enableTypes(true, false, false);
            break;
        case "BBQ":
            enableTypes(false, true, false);
            break;
        case "Chili":
            enableTypes(false, false, true);
    }

}


// WAGEN 2


if (nuFormType() == 'edit') {
    typeChanged();
}

var arrTypes = {
    Original: ['1W24'],  // <---- replace 2, 3 with your object IDs
    BBQ: ['1W25'], // <---- replace 4, 5 with your object IDs
    Chili: ['1W26']  // <---- replace 6, 7 with your object IDs
}

function enableType(Type, enable) {
    for (f in arrTypes[Type]) {
        nuEnable(arrTypes[Type][f], enable);
    }
}

function enableTypes(o, b, c) {
    enableType('Original', o);
    enableType('BBQ', b);
    enableType('Chili', c);
}

function typeChanged() {

    var type = $("#1W21 option:selected").text();  // <---- replace 1 with your select's object ID.
    switch (type) {
        case "Original":
            enableTypes(true, false, false);
            break;
        case "BBQ":
            enableTypes(false, true, false);
            break;
        case "Chili":
            enableTypes(false, false, true);
    }
Post Reply