Skip to main content
12-Amethyst
October 16, 2014
Solved

Adding javascript validation using DataUtilities on create wizard

  • October 16, 2014
  • 2 replies
  • 10179 views

Hi all,

I have a requirement of driver and dependent attributes which is based on selection of one value from combobox other attribute values should get populated. I'm referring to this solution https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS64401.

So I have created a data utilities class which is mapped to my driver attribute. And from that I can able to

call my javascript function which I have added in jsp page.

And that onchange validation also working fine. But my javascript function is not changing the value of other attribute.

Here is my javascript function.

<script type="text/javascript">

function customChangefunction(){

var target = window.document.getElementsByName("resultCombo");

var src = window.document.getElementById("sampleCombo");

var strUser = src.options[src.selectedIndex].value;

alert(strUser);

var colours = new Array('Black', 'White', 'Blue');

var shapes = new Array('Square', 'Circle', 'Triangle');

var names = new Array('John', 'David', 'Sarah');

switch (strUser) {

case 'one':

target.options.length = 0;

for (i = 0; i < colours.length; i++) {

createOption(target, colours[i], colours[i]);

}

break;

case 'two':

target.options.length = 0;

for (i = 0; i < shapes.length; i++) {

createOption(target, shapes[i], shapes[i]);

}

break;

case 'three':

target.options.length = 0;

for (i = 0; i < names.length; i++) {

createOption(target, names[i], names[i]);

}

break;

default:

target.options.length = 0;

break;

}

}

function createOption(ddl, text, value) {

var opt = document.createElement("OPTION");

opt.value = value;

opt.text = text;

ddl.options.add(opt);

opt.appendChild(text);

document.getElementById(ddl).appendChild(opt);

}

</script>

Can some tell me this is the correct way of doing it. And why this js function not working? From onchange I'm getting

the selected value.

And I have one more doubt if my dependent attribute is already having some values will this override and populate what we give here?

Please suggest me some solution.

Best answer by KD_01

Hi Vino,

First you make the driver attribute a Enumerated Value list then thriugh javascript you first remove the value and again populate the value with the required one.

function customChangefunction(){

var target = window.document.getElementsById("resultCombo");

var src = window.document.getElementById("sampleCombo");

var strUser = src.options[src.selectedIndex].value;

alert(strUser);

var colours = new Array('Black', 'White', 'Blue');

var shapes = new Array('Square', 'Circle', 'Triangle');

var names = new Array('John', 'David', 'Sarah');

while (target.options.length) {

target.remove(0);

}

switch (strUser) {

case 'one':

for (i = 0; i < colours.length; i++) {

createOption(target, colours[i], colours[i]);

}

break;

case 'two':

for (i = 0; i < shapes.length; i++) {

createOption(target, shapes[i], shapes[i]);

}

break;

case 'three':

for (i = 0; i < names.length; i++) {

createOption(target, names[i], names[i]);

}

break;

default:

target.options.length = 0;

break;

}

}

function createOption(ddl, text, value) {

var opt = new Option(value,text);

dd1.options.add(opt);

}

Added one document for similar type of job.

Regards,

Kaushik

2 replies

KD_0112-AmethystAnswer
12-Amethyst
October 17, 2014

Hi Vino,

First you make the driver attribute a Enumerated Value list then thriugh javascript you first remove the value and again populate the value with the required one.

function customChangefunction(){

var target = window.document.getElementsById("resultCombo");

var src = window.document.getElementById("sampleCombo");

var strUser = src.options[src.selectedIndex].value;

alert(strUser);

var colours = new Array('Black', 'White', 'Blue');

var shapes = new Array('Square', 'Circle', 'Triangle');

var names = new Array('John', 'David', 'Sarah');

while (target.options.length) {

target.remove(0);

}

switch (strUser) {

case 'one':

for (i = 0; i < colours.length; i++) {

createOption(target, colours[i], colours[i]);

}

break;

case 'two':

for (i = 0; i < shapes.length; i++) {

createOption(target, shapes[i], shapes[i]);

}

break;

case 'three':

for (i = 0; i < names.length; i++) {

createOption(target, names[i], names[i]);

}

break;

default:

target.options.length = 0;

break;

}

}

function createOption(ddl, text, value) {

var opt = new Option(value,text);

dd1.options.add(opt);

}

Added one document for similar type of job.

Regards,

Kaushik

VINO12-AmethystAuthor
12-Amethyst
October 17, 2014

Thanks a lot kaushik for your solution and document.

If possible please share the source code mentioned in document related to this.

Anyway I will try your suggestion and let you know.

12-Amethyst
October 17, 2014

Source codes are already inside the word document.

In case of any problem let me know I will upload them again .

1-Visitor
December 26, 2016

Hi Vino / Kaushik,

Similar type of requirement we have.

Our requirement is like below, Country, State, City are attributes on Problem Report page. when we select Country respective States from that country should display in States drop down and when we select the Appropriate State from drop down, City's belongs to that state should display in next city's drop down,

we are referring Kaushik's approach and able to populate Country's Drop down so far, but we are facing issues when we are trying to populate States drop down.

Please help us to solve this issue.

Regards,

Vivek

1-Visitor
December 3, 2020

Hello  Granite ,

 

I am also getting country dropdown properly but facing issue with State dropdown.Have you resolved this issue.

 

@Kaushik,

 

Please suggest .

17-Peridot
December 3, 2020

Since Windchill 11.1 you are able to configure this in the type and attribute manager (called: Cascading Attributes)

You don't need to do it with java script anymore.