How can I create a single Datepicker in svelte with carbon-components with german locale - datepicker

When I try to use the "Datepicker" in svelte with carbon-components I can configure the output to be set in a german locale style but after sending the form, the datepicker only shows "Please match the requested format." I am missing something but I really don`t now what I am missing.
Here is my code
<script lang="ts">
import { DataTable, DatePicker, DatePickerInput, NumberInput, Grid, Row, Column, Button, FluidForm } from "carbon-components-svelte";
let datum: Date;
</script>
<Grid>
<Row>
<Column>
<form>
<DatePicker
format="de-CH"
dateFormat="d.m.Y"
locale="de"
datePickerType="single"
flatpickrProps={
{
locale:
{firstDayOfWeek: 1},
dateFormat: "d.m.Y",
}
}
on:change bind:value={datum}
>
<DatePickerInput labelText="Datum" placeholder="dd.mm.yyyy" />
</DatePicker>
<Button size="small" type="submit">Submit</Button>
</form>
</Column>
</Row>
</Grid>
Screenshot of the error message:
When I remove the formatting stuff, the form works and the date is getting send.
This is a example without formatting with german locale
<script lang="ts">
import { DataTable, DatePicker, DatePickerInput, NumberInput, Grid, Row, Column, Button, FluidForm } from "carbon-components-svelte";
let datum: Date;
</script>
<Grid>
<Row>
<Column>
<form>
<DatePicker
datePickerType="single"
flatpickrProps={
{
locale:
{firstDayOfWeek: 1},
}
}
on:change bind:value={datum}
>
<DatePickerInput labelText="Datum" placeholder="dd.mm.yyyy" />
</DatePicker>
<Button size="small" type="submit">Submit</Button>
</form>
</Column>
</Row>
</Grid>
What am I missing? How can I use german locale with a german date format without getting the Error "Please match the requested format."?

These locale settings consist of various direct props that should be set:
DatePicker: locale & dateFormat
DatePickerInput: pattern
The flatpickr package also provides a large set of locales, I would recommend passing the German one directly to get day and month names.
import { German } from 'flatpickr/dist/l10n/de.js'; // there also is an ESM dir
<DatePicker locale={German} dateFormat="d.m.Y" ...>
<DatePickerInput pattern={'\\d{2}\\.\\d{2}\\.\\d{4}'} .../>
</DatePicker>
REPL
The pattern determines the regular expression used to check the value, so that has to match the input/dateFormat. (Pattern is passed in a string because of the curly braces within, which would cause Svelte to interpolate the number literals otherwise.)

Related

How to disable autocomplete with v-form

I want to disable chrome autocomplete in my v-form. How do I do that? I don't see a autocomplete property on the v-form.
https://next.vuetifyjs.com/en/api/v-form/
While it is a property on a normal html form
https://www.w3schools.com/tags/att_form_autocomplete.asp
By setting autocomplete="username" and autocomplete="new-password" on v-text-field you can actually turn off the autocomplete in chrome.
here is a code that worked for me:
<v-form lazy-validation ref="login" v-model="validForm" #submit.prevent="submit()">
<v-text-field
v-model="user.email"
label="Email"
autocomplete="username"
/>
<v-text-field
v-model="user.password"
label="Password"
type="password"
autocomplete="new-password"
/>
<v-btn type="submit" />
</v-form>
Edit: autocomplete isn't set as a prop in vuetify docs but if you pass something to a component which isn't defined as prop in that component, it will accept it as an attribute and you can access it through $attrs.
here is the result of the above code in vue dev tools:
and here is the rendered html:
I wasn't able to get autofill disabled with the above methods, but changing the name to a random string/number worked.
name:"Math.random()"
https://github.com/vuetifyjs/vuetify/issues/2792
use autocomplete="off" in <v-text-field
<v-text-field
autocomplete="off"
/>
Just add:
autocomplete="false"
to your <v-text-field> or any input
autocomplete="null"
This one prevents Chrome autofill feature
I have not been able to get any of the previous proposals to work for me, what I finally did is change the text-flied for a text-area of a single line and thus it no longer autocompletes
Try passing the type='search' and autocomplete="off" props.
I also ran into a similar problem. Nothing worked until I found this wonderful Blog "How to prevent Chrome from auto-filling on Vue?" by İbrahim Turan
The main catch is that we will change the type of v-text-field on runtime. From the below code you can see that the type of password field is assigned from the value fieldTypes.password. Based on focus and blur events we assign the type of the field. Also, the name attribute is important as we decide based on that in the handleType() function.
I'm also pasting the solution here:
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<template>
<div id="app">
<div v-if="isloggedin" class="welcome">
Welcome {{username}}
</div>
<div v-else id="form-wrapper">
<label for="username">Username: </label>
<input
v-model="username"
class="form-input"
type="text"
name="username"
value=""
autocomplete="off"
/>
<label for="password">Password: </label>
<input
v-model="password"
class="form-input"
:type="fieldTypes.password"
name="password"
value=""
#focus="handleType"
#blur="handleType"
autocomplete="off"
/>
<button class="block" type="button" #click="saveCredentials">
Submit Form
</button>
</div>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
username: '',
password: '',
isloggedin: false,
fieldTypes: {
password: 'text',
}
}
},
methods: {
saveCredentials() {
this.isloggedin = true;
},
handleType(event) {
const { srcElement, type } = event;
const { name, value } = srcElement;
if(type === 'blur' && !value) {
this.fieldTypes[name] = 'text'
} else {
this.fieldTypes[name] = 'password'
}
}
}
}
</script>

sap.ui.table.Column Regards Only Last Control and Expression Binding Doesn't Work

I have a column in a sap.ui.table.Table. In this column, I want to display my template control depending on the value. If I have a typeof DateTime, I want to use the DatePicker, typeof DateTime a DateTimePicker, and so on.
Now I want to differ it in my XMLView / Fragment but it only checks my last control (DateTimePicker):
<table:template>
<Input id="masterDataValueInput"
value="{thingDetail>value}"
placeholder="{path:'thingDetail>type', formatter:'.formatter.placeHolderFormatter'}"
visible="{= ! ${path: 'thingDetail>properties'} && ${path: 'thingDetail>type', formatter: '.formatter.inputVisibility'}}"
enabled="{appView>/isCurrentTenant}"
type="{path:'thingDetail>type', formatter:'.formatter.inputTypeFormatter'}"
/>
<DatePicker id="masterDataValueDate"
value="{thingDetail>value}"
displayFormat="short"
visible="{= ! ${path: 'thingDetail>properties'} && ${path: 'thingDetail>type', formatter: '.formatter.dateVisibility'}}"
enabled="{appView>/isCurrentTenant}"
change="handleChange"
/>
<DateTimePicker id="masterDataValueDateTime"
value="{thingDetail>value}"
displayFormat="short"
visible="{= ! ${path: 'thingDetail>properties'} && ${path: 'thingDetail>type', formatter: '.formatter.datetimeVisibility'}}"
enabled="{appView>/isCurrentTenant}"
change="handleChange"
/>
</table:template>
So the <Input> and the <DatePicker> controls are never displayed..
The methods in my formatter are never called either.
The reason why only the last control (DateTimePicker) is taken into account is because the template aggregation of sap.ui.table.Column awaits only a single control (0..1).
In order to make use of all three controls, you'll have to wrap them together in another container / layout control such as HorizontalLayout:
<table:template>
<layout:HorizontalLayout>
<!-- your controls -->
</layout:HorizontalLayout>
<table:template>
About the expression binding..
Try with parts:
visible="{= !${thingDetail>properties} && ${parts: [{path: 'thingDetail>type'}], formatter: '.formatter.inputVisibility'}}"
If that didn't call the formatter, toss that expression binding (as it's become hard to read anyway) and go for the usual property binding with the appropriate formatter:
visible="{
parts: [
'thingDetail>properties',
'thingDetail>type'
],
formatter: '.formatter.myFormatter'
}"

display a date on an edit from from mongo using ejs

There is an edit page where a user can, obviously, edit aspects of an event. Everything displays fine except the Date shows empty.
I am using the type="date" in my html which may be a cause, how can I get around this so that I can show the date, because when it saves it saves as null after editing the event
View:
<div class="form-group">
<input class="form-control" type="date" name="editEvent[startDate]" placeholder="Date" value="<%= event.startDate %>">
</div>
Route:
router.get("/event/:id/edit", isLoggedIn, function(req,res){
Event.findById(req.params.id, function (err, foundEvent) {
if(err){
console.log(err);
console.log("Cannot find the event...maybe the database isnt running?")
} else {
res.render("eventEdit", {event: foundEvent});
Everything works fine but the date
Can you add some more information to the question? at the moment it looks quite unclear. like how is your server set up.
It turns out its an HTML thing, if you want to display a date you have to have it formattted as YYYY-MM-DD then it shows fine, otherwise it doenst recognize the format.
This comes into account if you use the type="date" attribute in your input
I had to edit the event date coming from mongo using momentjs and here is the line I used.
var newDate = moment(foundEvent.startDate).utc().format("YYYY-MM-DD")
res.render("eventEdit", {event: foundEvent, newDate:newDate});
The newDate is the variable being passed to the template, then I just have:
<input class="form-control" type="date" name="editEvent[startDate]" placeholder="Date" value="<%= newDate %>">
This works.

Umbraco XSLT search page navigation using input onchange

I have created a pagination input that on change will go to the value entered into the input.
It will detect the page range and allow navigation between those pages in that range.
e.g /image-gallery-album-1.aspx?page=3
<form type="get" onchange="return false">
<div class="pagerUI">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<!-- previous page -->
<xsl:if test="$page > 1">
<td class="pager-prev"><a class="previous" href="{concat('?page=', $page - 1, $qs)}" title="Previous page">‹</a></td>
</xsl:if>
<td>Page</td>
<td><input type="number" name="page" id="page" min="1" >
<xsl:choose>
<xsl:when test="$page=1">
<xsl:attribute name="value">1</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="value"> <xsl:value-of select="$currentPageNumber" /> </xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="max"> <xsl:value-of select="$numberOfPages"/> </xsl:attribute>
</input></td>
<td>of <xsl:value-of select="$numberOfPages"/></td>
<!-- next page -->
<xsl:if test="$page * $resultsPerPage < count($matchedNodes)">
<td class="pager-next"><a class="next" href="{concat('?page=', $page + 1, $qs)}" title="Next page">›</a></td>
</xsl:if>
</tr>
</table>
</div>
</form>
However, when I added this to the XSLTSearch code it doesn't work as the URL loses the search string.
So instead of navigating to: /image-search.aspx?search=football&page=3
It navigates to: /image-search.aspx?page=3 Which doesn't display any results on that page as it's missing the search criteria to display the search results.
I tried to change the form and include an "action" that would change the URL to include the search value but I can't include the input value as it's dynamic.
For example with the below form if I enter any value into the input the URL updates to following: /image-search.aspx?search=otbra&page= It's missing the entered number of the input value.
Search form with onchange and action and method post attributes:
<form type="get" onchange="return false">
<xsl:attribute name="method"> <xsl:text>post</xsl:text> </xsl:attribute>
<xsl:attribute name="action"> <xsl:text>?search=</xsl:text> <xsl:value-of select="$search"/><xsl:text>&</xsl:text>page= (input value)</xsl:attribute>
Is there some javascript or some way of detecting the value submitted and parsing it into the search string of the URL?
Any assistance would be appreciated. Cheers, JV
NOTE: As comment on your post says the likely issue is with the $qs variable, however here's an explanation of how you can get Query String values in Umbraco, for reference.
In Umbraco you can retrieve a Query string value in XSLT using umbraco.library
So to retrieve the value of search you would call something like:
<xsl:variable name="searchValue" select="umbraco.library:RequestQueryString('search')"/>
This creates a variable called searchValue which you can then use to re-inject the query string value in your url.
Something like this:
<a class="next" href="{concat('?page=', $page + 1, '&search=', $searchValue)}" title="Next page">›</a>
More information on umbraco.library can be found on the our.umbraco.org site.

dynamically creating ids of macro components using arguments

I am trying to create two grids which perform exactly the same function without having to duplicate the code of the code for the grid twice. So, I decided to use a macro component. But, I am not sure how to create the ids of the components in the macro component dynamically. The code does the following:
The first grid(west region) has two rows with two textboxes. If I add "hello" to the first textbox in this grid then the value of the second textbox is also set to "hello".
The second grid(center region) has two rows with two textboxes. If I add "world" to the first textbox in this grid then the value of the second textbox is also set to "world"
The values of both textboxes in the first grid are now same i.e. "hello"
The values of both textboxes in the second grid are now same i.e. "world"
I created a zul file in which I use a macro component like so:
<?component name="mygrid1" macro-uri="grid1.zul" inline="true"?>
<zk>
<vbox hflex="1">
<borderlayout height="500px" width="500px">
<west size="50%">
<mygrid1 id="grid1" index="1" />
</west>
<center>
<mygrid1 id="grid2" index="2" />
</center>
</borderlayout>
</vbox>
</zk>
<zscript>
fillInDuplicateBox(String value, Textbox duplicateBox) {
if (!"".contentEquals(duplicateBox.value))
return;
duplicateBox.value = value;
}
</zscript>
</window>
Macro component is shown below:
<zk>
<vbox hflex="1">
<grid width="300px">
<rows>
<row> Box 1: <textbox id="${concat("newBox", arg.index)}" onChange="fillInDuplicateBox(${concat("newBox, arg.index)}.value, ${concat("duplicateBox", arg.index)})" hflex="1" /></row>
<row> Box 2: <textbox id="${concat("duplicateBox", arg.index)}" hflex="1" /></row>
</rows>
</grid>
</vbox>
</zk>
I also tried the following code to create the macro component
<zk>
<vbox hflex="1">
<grid width="300px">
<rows>
<row> Box 1: <textbox id="newBox${arg.index}" onChange="fillInDuplicateBox(newBox${arg.index}.value, duplicateBox${arg.index})" hflex="1" /></row>
<row> Box 2: <textbox id="duplicateBox${arg.index}" hflex="1" /></row>
</rows>
</grid>
</vbox>
</zk>
None of this works. I am not sure how to dynamically create the ids of the components in the macro component. The textbox ids of the first grid must be "newBox1", "duplicateBox1" and the textbox ids of the second grid must be "newBox2", "duplicateBox2"
Please point out if there is a better way of achieving this task.
Thanks,
Sony
I am not sure if it is possible to dynamically create ids like that, but I am pretty certain it would be better to avoid it. There are better ways to do this by avoiding the id problem altogether and to use data binding or event handling instead. Your example indicates the main purpose for each grid is to copy the value of one Textbox to a different Textbox - I imagine there is something bigger you are trying to achieve so let us know if this answer leads you to what you need or not.
I have simplified and expanded your sample to give two examples, the first uses the onChanging to immediately copy as you type. The second pair of boxes uses databinding.
<?component name="mygrid1" macro-uri="/grid1.zul" ?>
<zk>
<window>
<vbox hflex="1">
<mygrid1 id="grid1" myGridTitle="First" />
<mygrid1 id="grid2" myGridTitle="Another" />
</vbox>
</window>
</zk>
Here is the macro component in grid1.zul:
<zk>
<zscript><![CDATA[
String myBoundString = "initial value";
]]></zscript>
<vbox hflex="1">
<grid>
<rows>
<row>
<hbox><label value="${arg.myGridTitle}" /> Source</hbox>
<textbox id="originalText" hflex="1" onChanging="duplicateText.value = event.value" />
</row>
<row>
<hbox><label value="${arg.myGridTitle}" /> Source copies here:</hbox>
<textbox id="duplicateText" hflex="1" />
</row>
<row>
Bound to myBoundString:
<textbox id="boundText1" value="#{myBoundString}" hflex="1" />
</row>
<row>
Bound to boundText1:
<textbox id="boundText2" value="#{boundText1.value, load-when=boundText1.onChange}" hflex="1" />
</row>
</rows>
</grid>
</vbox>
</zk>
In the databinding example, you have to change "intial value" and then tab away before the binder updates boundText2. Also notice that the TextBoxes do have ids (boundText1 and boundText2) but that has no impact on achieving the expected functionality in multiple instances of the macro component.