내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Setting pattern in a script

Avatar

Level 5

Along with rounding up I'm trying to set a the pattern of a field in a form based on the number entered.  I.E. if the field is <10 then use 1 decimal; if 10 or greater use 0 decimals. So basically,  if 0.47 is entered it will round to 0.5.  Likewise if 2.84, it would round to 2.8.  But if 10.85 is entered it would round to 11 and 25.83 would round to 26 because both are greater than 10.  Can this be done?

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Employee

Hi, @ReluctantProgrammer 

 

@Pulkit_Jain_ has shown you a JS function which will modify the value which you would then put into the field.

There is an alternative approach. Assuming that this is an interactive form you use a Numeric Field and then place the following script in the Exit event:


if (this.rawValue <10) {
this.format.picture.value = "num{z,zzz,zz9.9}";
} else {
this.format.picture.value = "num{z,zzz,zz9}";
}

 

This will not change the value, only the display pattern.

Kosta_Prokopiu1_0-1625038691823.png

The result for your numbers:

Kosta_Prokopiu1_2-1625038973540.png

 

 

 

원본 게시물의 솔루션 보기

3 답변 개

Avatar

Employee Advisor

@ReluctantProgrammer 

You can implement something like below on the field exit event of your form:

function myFunction() {
  var num = [Field Value Input];
  if (num<10)
  {
  var n = num.toFixed(1);
  } else
  { 
var n = num.toFixed(0);
  }

 

Hope this helps!

Avatar

정확한 답변 작성자:
Employee

Hi, @ReluctantProgrammer 

 

@Pulkit_Jain_ has shown you a JS function which will modify the value which you would then put into the field.

There is an alternative approach. Assuming that this is an interactive form you use a Numeric Field and then place the following script in the Exit event:


if (this.rawValue <10) {
this.format.picture.value = "num{z,zzz,zz9.9}";
} else {
this.format.picture.value = "num{z,zzz,zz9}";
}

 

This will not change the value, only the display pattern.

Kosta_Prokopiu1_0-1625038691823.png

The result for your numbers:

Kosta_Prokopiu1_2-1625038973540.png

 

 

 

Perfect! Thank you so much!!