Code to change field date size if equal to today

260
3
08-26-2021 07:30 AM
JoeLivoti
New Contributor III

In the details box, How might I code something so that if the date equals {today} that the text would change size? thank you

0 Kudos
3 Replies
jcarlson
MVP Notable Contributor

Where exactly are you trying to implement this? Depending on what widget you're working with, this may be doable, but the means of accomplishing it may differ. In an Indicator, for example, this is pretty easy.

- Josh Carlson
Kendall County GIS
0 Kudos
JoeLivoti
New Contributor III

JoeLivoti_0-1629988866506.png

in this details box. as you can see they are currently ordered by date with newest on top. I'd like to make the next bigger if the date = today's date so as to draw attention to it.

0 Kudos
jcarlson
MVP Notable Contributor

Should be simple enough in a list, too. You just need a quick expression to evaluate the date field against today's date, then push a value into a returned attribute.

 

var the_date = $datapoint["sale_date"]

var text_size = "10px"

if(the_date >= today()){
    text_size = "16px"
}

return {
  attributes: {
    text_size: text_size
  }
}

 

Once you have this, the next step is to edit your list viewing the HTML source, then using that returned attribute to define a span of text.

 

<p>{document_number}</p>
<p style="font-size:{expression/text_size}">{sale_date}</p>

 

My sample data doesn't have any current data, so I've set mine to an arbitrary date so you can see it working.

jcarlson_0-1629990437684.png

 

- Josh Carlson
Kendall County GIS