Placeholder in Types.Text in keystone - keystonejs

Help, Every one I am new in keystone while defining the model I am not able to put the placeholder text in the TYPES.TEXT model. I do not know the syntex. Please help me.
product.add({
title: {type: String, required: true},
description: {type: Types.Text,},
});

As per http://keystonejs.netlify.com/api/field/options/
All field types in Keystone have several common options one of which is setting the default value for the field. If you add default: 'Your Default Text Here" the default value for that filed if nothing else is submitted would be Your Default Text Here.
product.add({
title: {type: String, required: true},
description: {type: Types.Text, default: 'Your Default Text Here'},
});

Related

How does one use the "Content" field type in KeystoneJS?

How does one use the Content field type in KeystoneJS? I've put the following in my index.js, following the example given in the link above:
keystone.createList('Todo', {
schemaDoc: 'A list of things which need to be done',
fields: {
name: {type: Text, schemaDoc: 'This is the thing you need to do'},
blip: {type: Text, schemaDoc: 'This is another thing'},
status: {type: Select, options: 'pending, processed'},
rating: { type: Stars, starCount: 5 }, body: {
type: Content,
blocks: [
Content.blocks.blockquote,
Content.blocks.image,
Content.blocks.link,
Content.blocks.orderedList,
Content.blocks.unorderedList,
Content.blocks.heading,
// CloudinaryImage.blocks.image,
],
},
},
But when I go to the front end and click on the '+' button there, it only offers me the option of inserting an image (see screenshot below)
What is it I'm supposed to be seeing? If I'm supposed to see more, what am I supposed to be doing? I don't see anything about 'blockquote', 'link', 'orderedList', etc....
Is this all superceded by the Wysiwyg editor? Or do they do different things?
you have to write some text and then select that text for text formatting items.
this is how it looks with all options on:
this is how it looks when I remove the extra formatting option (bare content field)

How to get radiobutton by default checked with bootbox prompt

I am able to display radio buttons using bootbox prompt. But I am not getting the checked radio button by default. How to do that . Here is my code to displaying radio buttons.
bootbox.prompt({
title: "This is a prompt with a set of Radiobutton inputs!",
inputType: 'radio',
inputOptions: [
{
text: 'EU Format',
value: '1',
checked: true,
},
{
text: 'Standard Format',
value: '2',
}
],
callback: function (result) {
console.log(result);
}
});
I have added checked: true, and tried with checked : "checked" , but not sure these both not working . Any help would be greatly appreciated.
This is actually covered in the documentation, here. I've also answered this previously, but since I don't have a link to that answer at the moment, this is what you need to do:
bootbox.prompt({
title: "This is a prompt with a set of Radiobutton inputs!",
inputType: 'radio',
value: '1', /* value sets the initial checked item */
inputOptions: [
{
text: 'EU Format',
value: '1',
checked: true,
},
{
text: 'Standard Format',
value: '2',
}
],
callback: function (result) {
console.log(result);
}
});
The only difference between radiobuttons and checkboxes is that you can only set a single value with radios. NOTE THAT THE TYPES MUST MATCH. In your example, '1' would work, but 1 would not, since the former is a string, whereas the latter is a number. We don't do any explicit type coercion when checking the value attribute.
Since you're referencing the radio type, I assume you're using the 5.x version? If so, I have a work-in-progress update to the docs here, until I can push the 5.x version out. The old docs are still valid, but it (obviously?) doesn't document some of the new features.

Unique field types and specific GET-parameters for api calls in Apostrophe CMS

I have several questions about Apostrophe CMS:
Is it possible to add a unique field type in apostrophe-pieces? I can't find a way to do this.
Edit: I noticed that I wasn't specific enough. I want to make sure that there can't be two instances in the database with the same value in an added field. It should be something like an additional id. Is there an option for this? Maybe something like:
addFields: [
{
name: 'secondId',
label: 'Second ID',
type: 'string',
required: true,
unique: true
}
]
I want to access the apostrophe-headless api and get a specific element by passing a certain value of one of the created field types of the correspondent piece in a GET-parameter. Is something like this possible?
For example:
Piece:
module.exports = {
extend: 'apostrophe-pieces',
name: 'article',
label: 'Article',
pluralLabel: 'Articles',
restApi: {
safeFor: 'manage'
},
addFields: [
{
name: 'title',
label: 'Name',
type: 'string',
required: true
},
{
name: 'author',
label: 'Author',
type: 'string',
required: true
}
]
};
Desired api call for getting all articles which have strored "Jon" as author:
http://example.com/api/v1/article?author=Jon
Thank you very much in advance!
Custom field types
You can add custom field types at project level by extending apostrophe-schemas and adding the proper definition. You'll need to add a converter for server-side sanitization and a populator for the front-end of the form field.
You can follow the examples in Apostrophe's schema module, linked are the functions defining a float
https://github.com/apostrophecms/apostrophe/blob/0bcd5faf84bc7b05c51de7331b17f5929794f524/lib/modules/apostrophe-schemas/index.js#L1367
https://github.com/apostrophecms/apostrophe/blob/0bcd5faf84bc7b05c51de7331b17f5929794f524/lib/modules/apostrophe-schemas/public/js/user.js#L991
You would add your definitions in your project level lib/modules/apostrophe-schemas's index.js and public/js/user.js respectively.
Filtering
You can search your piece index for a string like Jon by adding ?search=jon to your query but more likely you want to filter pieces by the value of a join.
If you had piece types article and authors, you could have a joinByOne field in article's schema that lets you relate that article to an author piece. Then, by enabling pieceFilters you could filter directly on those joined properties.
A complete rundown of piecesFilters can be found here https://apostrophecms.org/docs/tutorials/intermediate/cursors.html#filtering-joins-browsing-profiles-by-market
I think you'd also need to mark that filter as safe for api use in your apostrophe-headless configuration https://github.com/apostrophecms/apostrophe-headless#filtering-products

KeystoneJS dependsOn not saving its new value when disappear

User.add({
name: { type: Types.Name, required: true },
userid: { type: Types.Text, initial: true, required: true },
exceed_login_attempt: {
type: Types.Boolean,
default: false,
label: 'Exceeded Invalid Login Attempts',
dependsOn: { exceed_login_attempt: true }
}
});
I have here a checkbox input field exceed_login_attempt I want this to be display in AdminUI if the value is true (checked). If I unchecked that the value is false and the checkbox will disappear - this is fine.
But when I save it the checkbox value which is false is not save. After rendering the page the value is still true, which means it displays again the checkbox.
On KeystoneJS database documentation it is mentioned that:
To improve the usability of the Admin UI, it is possible to hide fields when no value is set, or depending on the value of other fields.
A field can depend on the value of other fields. But in your posted code, the exceed_login_attempt field, depends on its own value, which doesn't look right to me:
exceed_login_attempt: {
...
dependsOn: { exceed_login_attempt: true }
}
I'm not sure, maybe you intend to use collapse rather than dependsOn:
collapse [Boolean] Displays an + add link in the admin UI when the field has no value. Will completely hide field UI when noedit is also set to true, when the field has no value

What is the trick to changing currency of CurrencyTextBox

I have a CurrencyTextBox where I set the currency to a default currency. The user can change it by making a selection in a currency drop down on same form. I thought I could just change the currency attribute on the textbox dynamically but nothing happens. The symbol will not change. Is there some trick to make this work? I've seen related posts that had to destroy and recreate the widget. Seems like there might be a better way?
I'd like to set the currency of unitCostId widget to the user's selected currency on the fly. The result would be that the currency symbol would change to match the newly selected currency.
new CurrencyTextBox ({
id: "unitCostId",
name: "price",
currency: "USD",
required: true,
value: "",
placeHolder: "Enter Price"
}, "unitCostNode");
----------------------------------------------------
new Select({
id: "currencyOptionsId",
name: "currency_code",
value: "USD",
options: currencyOptions,
required: true,
onChange: function(val) {
var currency_id = this.get("value");
registry.byId("unitCostId").set("currency",this.get("value");
// registry.byId("unitCostId").reset();
}
}, "currencyNode");
Any help would be appreciated!
Unfortunately, the currency property has no setter logic, and is documented as constant. However, due to how the underlying code works, you can still manage to change it by setting it via constraints instead:
registry.byId("unitCostId").set("constraints", { currency: this.get("value") });