6/1/2019
Posted by 

This video will teach you how to knockout text in Cricut Design Space. Leave comments below of you have any questions. Also, let me know if there are any videos that you would like me to make.

In knockout.js I have a very standard field that looks like this:

What I'd like is to have a default value specified in here if the text value is null, for example 'No Job Title Specified'.

Knock Out Texture

Is this possible to do in knockout.js?

Thanks.

Adam LevittAdam Levitt

7 Answers

So I'm guessing you want a real default value and not just a placeholder text. Here's a way to do that with an extender;

Hope this helps.

madcapnmckaymadcapnmckay

The shortest / easiest way is probably:

Knock Out Textured Ceilings

Working example:

Or JS Fiddle: http://jsfiddle.net/735qC/43/

rjmunrorjmunro

Even shorter than other code samples is the following:

With the initiation

K. RohdeK. Rohde

You can do it like this:

Knockout text in photoshop

With the undefined control, you can check whether you have that function or not when you are loading the page for the first time.

Bura ChuhadarBura Chuhadar

It might be useful to have a default value for display purposes only, instead of applying extenders which always return a default value.

With this, properties of your model remain empty, which is better for example when it comes to validation (checking for empty properties) or sending data back to the server (you might not want to send back this default value).

You could use the custom binding in the following example, which is based on the text binding, which renders a supplied default text or - if not supplied (you could adjust this to your needs of course):

Philip BijkerPhilip Bijker

I ran into this when returning data for a table, but only having some columns sortable.

This says that, for each column in the table's header, add the class 'active' if 'isActive' is defined and set to true, but don't freak out if it isn't there. The same goes for adding a 'href' attribute.

Disclaimer: I don't understand knockout well enough to know the limitations of this approach, but this worked for me in my case, whereas, the more straightforward approach of css: {active: isActive() '} threw errors.

JJ RohrerJJ Rohrer

To show the data in the input field, the easiest way is...

It errors but it works.. :)

speed_racerspeed_racer

Not the answer you're looking for? Browse other questions tagged data-bindingknockout.js or ask your own question.