#async function to render text

1 messages · Page 1 of 1 (latest)

gray vale
#

I'm trying to render some text in a attribute for a radio. The function has to be async because it had to do a post request .... currently this is what its outputting (I just printed what its printing in the label on the screen so you can see it)

How can I resolve the promise?

gray vale
#

So the library that I'm using .. uses a webworker to generate the mathML markup to speech.. thats why it's in a async

wraith stream
gray vale
#

So i don't know if thats going to help me because I'm trying to output to a label

#

I mean attribute

#

actually how do I get the value from the state?

#

this.state.resolved doesn't print anything

wraith stream
#
export default class Demo extends Component {
  get state() {
    return getPromiseState(readFromSomewhere);
  }

  <template>
    {{#if this.state.resolved}}
      <input type="radio">  
      <label some-attr={{this.state.resolved}}>Label</label> <-- this is the value
    {{/if}}
  </template>
}
wraith stream
gray vale
#

Ok one second

#

LOL I was a silly goose of course

wraith stream
#

working?

gray vale
#

well.. ran into another problem

#

I forgot that i was passing the value to the function as a paramter

wraith stream
#

should be fine to do that

#

what trouble are you having?

gray vale
#

How do I pass a value to the this.state function

#

should I create a {{ #let somevalue = answer.content}}

#
                        <div class="radio">
                            <label class="d-flex" for={{(concat "question-answer-text-" hi)}}>

 {{#if (fn this.woof.resolved answer.content)}}

                                <Input @type="radio" class="form-check-input" name={{(concat "question-answer-text-" @data._id)}} id={{(concat "question-answer-text-" hi)}} {{on "change"  (fn this.onSelectAnswer answer._id @data._id @data.domainId @catStartDate) }} aria-label={{this.woof.resolved}} />
                           
   
    {{/if}}
                                <div class="question-answer-text">
                                    
                                    <RichRender @data={{answer.content}}></RichRender>          
                                    
                                    {{!-- <Questions::MathjaxContent @content={{(render-html answer.content) }} />  --}}
                                </div> 
                            </label>
                        </div>
                    {{/each}}```
#

so my radio is in a each

#

I'm passing the value from the |answer| to this.woof

#

but this.woof.resolve is there

wraith stream
#

simplest way would be to turn it into a component with an arg

eg

export default class RadioOption extends Component {
  @cached
  get promise() {
    return this.doAsyncThing(this.args.answer);
  }

  get state() {
    return getPromiseState(this.promise);
  }

  <template>
    <Input @type="radio" class="form-check-input" aria-label={{if this.state.resolved this.state.resolved ''}} ...attributes />
  </template>
}
{{#each @data.possibleItemAnswers as |answer hi|}}
  <div class="radio">
    <label class="d-flex" for={{(concat "question-answer-text-" hi)}}>

      <RadioOption @answer={{answer}} name={{(concat "question-answer-text-" @data._id)}} id={{(concat "question-answer-text-" hi)}} {{on "change"  (fn this.onSelectAnswer answer._id @data._id @data.domainId @catStartDate) }} />

      <div class="question-answer-text">
        <RichRender @data={{answer.content}}></RichRender>          
      </div> 
    </label>
  </div>
{{/each}}
gray vale
#

I think I got it solved

#

You've gotten your self added to the end of the year Christmas gift list thankyou

gray vale
#

What library is @cached in ? I can't fidn it