ion datetime isDateEnabled is not working. i already added isDateEnabled in HTML, but not working.
here is my code -
== HTML ==
<ion-datetime [isDateEnabled]="isDateEnabled('2022-06-26T00:00:00.000Z')" [firstDayOfWeek]="1" presentation="date" ></ion-datetime>
=== TS file ===
isDateEnabled(dateIsoString: string) {
const date = new Date(dateIsoString);
if (getYear(date) === 2022) {
return false;
}
return true;
}
I hope you have a good day. You need to pass a function in the isDateEnabled property
.html
<ion-datetime [isDateEnabled]="isDateEnabled"></ion-datetime>
.ts
// arrow function allow access global scope
isDateEnabled = (dateIsoString: string): boolean => {
return true;
};
Related
Can anyone give where to look, or what I am missing, for how to use runTransaction in 9.0.3? (Flutter, Firebase realtime DB)
I updated firebase_database ^7.0.0 to ^9.0.3. Had to change runTransaction(MutableData mutable) to runTransaction(Object object), and the Object is null for Map data. Does return a String when point to single node of a String.
For something to work I placed + ‘/sap’ at end of .ref(…), and it gave ‘DROID’
Code Updated for Comment below:
bool bCanWeStartGame = false;
bool bIfiOS = false;
bIfiOS = Theme.of(referencedData.mngGamesPageMaterialContext)
.platform == TargetPlatform.iOS;
DatabaseReference playersRef = referencedData.database.ref(
TABLENAME_STARTS + '/' + referencedData.strFBGameUniqueIDKey);
if(bIfiOS){
//apparently iPhone needs to 'open line to DB record' to work
playersRef.once()
.then((DatabaseEvent event) {//dont need to do anything??
});
}
TransactionResult txResult;
//while loop to repeat runTransaction until solved
int iWhileLoopCheck = 0; //so whileLoop does not go forever
bool bTransactionCommittedOrGetOutAnyWay = false;
while(!bTransactionCommittedOrGetOutAnyWay
&& (iWhileLoopCheck<30)){
iWhileLoopCheck++;
txResult = await playersRef
.runTransaction(
(Object post) {
if (post == null) {
if(bIfiOS){sleep(Duration(milliseconds: 3));}
return Transaction.abort(); //out, but will retry transaction
}
Map<String, dynamic> _post = Map<String, dynamic>.from(post as Map);
bTransactionCommittedOrGetOutAnyWay = true; //whichever of
//options below take effect, dont want to continue while loop
if (_post[STARTS_TABLE_ALL_PLAYERS] !=
startingGames[iIndexInStartingGames].allplayers) {
//someone has joined since trying to start
bCanWeStartGame = false;
//Transaction.abort() as dont want to change data
return Transaction.abort();
} else {
//Nobody has joined, so can Start. Tell others Game is starting
_post['stg'] = true;
bCanWeStartGame = true;
return Transaction.success(_post);
}
});
} //while runtransaction doesnot get at data```
I'm using momentjs to work with dates in my project for when a user enters a date in M/D/YYYY format to revert to MM/DD/YYYY format (e.g. 2/5/2017 to 02/05/2017). I am also converting any invalid dates or dates greater than today to be reset back to today's date.
element.on("blur", function() {
var currentDate = moment().format('MM/DD/YYYY');
var formattedInput;
if (ctrl.$modelValue !== undefined && ctrl.$modelValue !== "") {
if(moment(ctrl.$modelValue, "MM/DD/YYYY", true).isValid()) {
formattedInput = moment(ctrl.$modelValue);
formattedInput.format('MM/DD/YYYY');
if (formattedInput.isAfter(currentDate)) {
ctrl.$setViewValue(currentDate);
ctrl.$render();
}
} else if (moment(ctrl.$modelValue, "M/D/YYYY", true).isValid()) {
formattedInput = moment(ctrl.$modelValue);
formattedInput.format('MM/DD/YYYY');
if (formattedInput.isAfter(currentDate)) {
ctrl.$setViewValue(currentDate);
ctrl.$render();
} else {
ctrl.$setViewValue(formattedInput.format('MM/DD/YYYY'));
ctrl.$render();
}
} else {
ctrl.$setViewValue(currentDate);
ctrl.$render();
}
}
});
As far as I can tell, this is all working fine with the code I have above. But regardless of working functionality, I am receiving the deprecation warning for non-ISO dates. My thoughts are the use of MM/DD/YYYY format, however this is unchangeable due to business requirements. Is there a way to remedy this issue in a non-cumbersome way?
The problem is with formattedInput = moment(ctrl.$modelValue) here you are using moment parsing without format with non-ISO dates. To remove the Deprecation warning, just use moment(ctrl.$modelValue, "MM/DD/YYYY") and moment(ctrl.$modelValue, "M/D/YYYY") as you have done in the if condition.
Your complete code will be the following:
element.on("blur", function() {
var currentDate = moment();
var formattedInput;
if (ctrl.$modelValue !== undefined && ctrl.$modelValue !== "") {
if(moment(ctrl.$modelValue, "MM/DD/YYYY", true).isValid()) {
formattedInput = moment(ctrl.$modelValue, "MM/DD/YYYY", true);
// This line returns a string, but does not assign to value, so it's superfluous
//formattedInput.format('MM/DD/YYYY');
if (formattedInput.isAfter(currentDate)) {
ctrl.$setViewValue(currentDate.format('MM/DD/YYYY'));
ctrl.$render();
}
} else if (moment(ctrl.$modelValue, "M/D/YYYY", true).isValid()) {
formattedInput = moment(ctrl.$modelValue, "M/D/YYYY", true);
// see previous comment
//formattedInput.format('MM/DD/YYYY');
if (formattedInput.isAfter(currentDate)) {
ctrl.$setViewValue(currentDate.format('MM/DD/YYYY'));
ctrl.$render();
} else {
ctrl.$setViewValue(formattedInput.format('MM/DD/YYYY'));
ctrl.$render();
}
} else {
ctrl.$setViewValue(currentDate.format('MM/DD/YYYY'));
ctrl.$render();
}
}
});
Be sure to fully understand the difference between moment parsing (build a moment object from a string) and moment format (display a string representation of a moment object).
When extending $firebaseArray I get the error 'invalid key $id (cannot contain .$[]#)'
The issue is with the $id property on the book object. When calling $save on the array and passing the modified book in, the factory doesn't recognize $id as the id field like it normally would prior to extending.
Html
<ul>
<li ng-repeat="book in bookList"> {{book.$id}}: {{book.date|date:"medium"}}
<button ng-click="setDate(book)">set date</button>
</li>
</ul>
<pre>{{book|json}}</pre>
Javascript
// reference to our Firebase instance
var fb = new Firebase('YourUrl');
function Book(snap) {
// records in synchronized arrays must have a $id property
this.$id = snap.key();
this.update(snap);
}
Book.prototype.update = function (snap) {
angular.extend(this, snap.val());
// convert json dates to Date objects
this.date = new Date(this.date||0);
this.$priority = snap.getPriority();
};
Book.prototype.toJSON = function() {
return angular.extend({}, this, {
// revert Date objects to json data
date: this.date.getTime()
});
};
var app = angular.module('app', ['firebase']);
app.controller('ctrl', function ($scope, bookFactory) {
// create a synchronized array with a customized version
// of $FirebaseArray
$scope.bookList = new bookFactory(fb);
// loads a single record for display
$scope.book = "Click on a book id";
$scope.loadBook = function (book) {
$scope.book = book;
};
// changes the date on a book record, note that we're working
// with Date objects here
$scope.setDate = function(book) {
book.date = new Date();
$scope.bookList.$save(book);
};
});
app.factory('bookFactory', function ($firebaseArray, $firebaseUtils) {
return $firebaseArray.$extend({
// override $$added to return a Book object
$$added: function (snap, prevChild) {
return new Book(snap);
},
// override $$updated to update the book object
$$updated: function (snap) {
var rec = this.$getRecord(snap.name());
if(angular.isObject(rec) ) {
book.update(snap);
}
}
});
});
Made a fiddle showing the error, just press 'Set Date' on any of the books.
https://jsfiddle.net/jensenben/h98mjsoz/
This can be remedied if make the book object use id instead of $id and add a $$getKey method to the $extend call to tell it what field has the id in it, but I'd prefer to stick with the traditional $id field that I use when not extending a $firebaseArray.
function Book(snap) {
// records in synchronized arrays must have a $id property
this.id = snap.key();
this.update(snap);
}
return $firebaseArray.$extend({
$$getKey: function(rec) {
return rec.id;
},
...
There's a bit much going on, so I'm not sure if this is your problem. But to get rid of the error, convert the $firebaseObject() to a regular JSON object when saving:
$scope.setDate = function(book) {
book.date = new Date();
$scope.bookList.$save(book.toJSON());
};
Note that the CSS and most of the JavaScript code are irrelevant to the problem.
I'm following a tutorial from here
For some reason when I try to create a new user with a date it won't accept it unless the month is January between dates ranging from 1-12ish.
I'm pretty sure it's because of the ValidationMessageFor(in the User.cs) method which forces me to enter a date which month must be January and I don't know where to alter it.
jquery.validate
jquery.validate.unobtrusive
Add code into script
$.validator.addMethod('date', function (value, element) {
if (this.optional(element)) {
return true;
}
var valid = true;
try {
$.datepicker.parseDate('dd/mm/yy', value);
}
catch (err) {
valid = false;
}
return valid;
});
$('#dt1').datepicker({ dateFormat: 'dd/mm/yy' });
I want to check in my function if a passed argument of type object is empty or not. Sometimes it is empty but still not null thus I can not rely on null condition. Is there some property like 'length'/'size' for flex objects which I can use here.
Please help.
Thanks in advance.
If you mean if an Object has no properties:
var isEmpty:Boolean = true;
for (var n in obj) { isEmpty = false; break; }
This is some serious hack but you can use:
Object.prototype.isEmpty = function():Boolean {
for(var i in this)
if(i != "isEmpty")
return false
return true
}
var p = {};
trace(p.isEmpty()); // true
var p2 = {a:1}
trace(p2.isEmpty()); // false
You can also try:
ObjectUtil.getClassInfo(obj).properties.length > 0
The good thing about it is that getClassInfo gives you much more info about the object, eg. you get the names of all the properties in the object, which might come in handy.
If object containes some 'text' but as3 doesn't recognize it as a String, convert it to string and check if it's empty.
var checkObject:String = myObject;
if(checkObject == '')
{
trace('object is empty');
}
Depends on what your object is, or rather what you expect it to have. For example if your object is supposed to contain some property called name that you are looking for, you might do
if(objSomeItem == null || objSomeItem.name == null || objSomeItem.name.length == 0)
{
trace("object is empty");
}
or if your object is actually supposed to be something else, like an array you could do
var arySomeItems = objSomeItem as Array;
if(objSomeItem == null || arySomeItems == null || arySomeItems.length == 0)
{
trace("object is empty");
}
You could also use other ways through reflection, such as ObjectUtil.getClassInfo, then enumerate through the properties to check for set values.... this class help:
import flash.utils.describeType;
import flash.utils.getDefinitionByName;
public class ReflectionUtils
{
/** Returns an Array of All Properties of the supplied object */
public static function GetVariableNames(objItem:Object):Array
{
var xmlPropsList:XMLList = describeType(objItem)..variable;
var aryVariables:Array = new Array();
if (xmlPropsList != null)
{
for (var i:int; i < xmlPropsList.length(); i++)
{
aryVariables.push(xmlPropsList[i].#name);
}
}
return aryVariables;
}
/** Returns the Strongly Typed class of the specified library item */
public static function GetClassByName($sLinkageName:String):Class
{
var tObject:Class = getDefinitionByName($sLinkageName) as Class;
return tObject;
}
/** Constructs an instance of the speicified library item */
public static function ConstructClassByName($sLinkageName:String):Object
{
var tObject:Class = GetClassByName($sLinkageName);
//trace("Found Class: " + tMCDefinition);
var objItem:* = new tObject();
return objItem;
}
public static function DumpObject(sItemName:String, objItem:Object):void
{
trace("*********** Object Dump: " + sItemName + " ***************");
for (var sKey:String in objItem)
{
trace(" " + sKey +": " + objItem[sKey]);
}
}
//}
}
Another thing to note is you can use a simple for loop to check through an objects properties, thats what this dumpobject function is doing.
You can directly check it as follow,
var obj:Object = new Object();
if(obj == null)
{
//Do something
}
I stole this from a similar question relating to JS. It requires FP 11+ or a JSON.as library.
function isEmptyObject(obj){
return JSON.stringify(obj) === '{}';
}
can use use the hasProperty method to check for length
var i:int = myObject.hasProperty("length") ? myObject.length: 0;