Clear field and type in DalekJS - dalekjs

I'm relatively new to DalekJS and I've been battling with clearing a field, and then typing. The .type() seems to only add to an existing string in an input box, is there any way to clear the field before typing?

I thought I´d implemented this some time ago, but reading my own source code made it clear to me that this isn't the case.
As long as the clear() method is not implemented, you can use this function as a workaround:
.execute(function () {
document.getElementById('id-of-the-element').value = '';
})
That should do the trick.

better is to use jQuery otherwise you only can select id fields
$('#somedivid > span.some-class.other-class > form > input').val('');
See you

It does work with...
.setValue ('selector', 'value')

Related

add some custom information to node drupal 8

I need to update my referential entity with new values ​​that are inserted every time a user visits the page. I tried to use this code but unfortunately, the latter does not add a value but replaces all of them. I am attaching the code that I used in the hope that someone can help me with this problem. thank you
nodeObj = Node::load(implode($nids));
$nodeObj->set('my_field', $current_user_id);
$nodeObj->save();
If I understand your issue correctly, your code is overwriting the entire value of my_field rather than appending a new value. Also, the implode() and the $nids variable suggest to me that you may be trying to perform this function on multiple nodes at once, which your current code will not do.
Make sure my_field is an ItemList field of some kind.
Try this code:
$nodeObjs = Node::loadMultiple($nids);
foreach ($nodeObjs as $nodeObj) {
$nodeObj->my_field->appendItem($current_user_id);
$nodeObj->save();
}

Is it possible to show all options in Tokenize2?

Tokenize2 is a javacsript lib to select multiple options.
It provides a very neat UI to start writing and then get a list of options to select from. Selected options will show up as "tags" that can be removed with "x" link.
So far all is fine. But Right now you need to know what your looking for and start write at least one character to see matching alternatives.
In my scenario there are very few alternatives and they are not known to the user. I would like to show ALL options when the user clicks the input box. There is a configuration option named searchMinLength but it is already set to 0.
Is there a workaround that can be used? Maybe like triggering load and dropdown manually?
I know there are a lot of similar alternatives but I picked Tokenize2 because:
It looks clean and nice
It works in mobile browsers
I don't know if there is an "official" approach, but after some investigation I have found an acceptable workaround.
After downloading the Tokenizer2 sourceode I found the following line that triggered my attention:
if(this.input.val().length > 0){
this.trigger('tokenize:search', [this.input.val()]);
}
My interpretation is that the internal search command is not triggered unless the user input has at least one character. This line in sourcecode could easily be modified. I have filed a suggestion for this here: https://github.com/zellerda/Tokenize2/issues/26
My current workaround is to add an event listener for the select event and there trigger the internal search command. That works fine for my scenario and does not force a source code rewrite.
$("#my-dropdown").on("tokenize:select", function (e: Event, routedEvent: boolean) {
$("#my-dropdown").trigger('tokenize:search', "");
});
Tokenize2
This link worked for me GitHub
$('.tokenize-sample-demo1').on('tokenize:select', function(container){
$(this).tokenize2().trigger('tokenize:search', [$(this).tokenize2().input.val()]);
});

Update an Optional element to protobuffer

I'm using R for coding. I need to add/update an optional field in my protobuffer files. The function "add" works well for repeated fields; but it does not seem to be compatible for optional fields.
example:
A$add("gender", X["gender"]); # Works if A is repeated; but not when it's optional!
Do you know what function I should use for this purpose?
Thanks
try the following
A$set("gender", X["gender"]);
I found the solution!
If "add" does not work, you should try:
A$gender = X["gender"];
Should work!
Thanks
The optional field already exists. You only need to assign a value to it.

Add a timestamp and info to a saved CSS/HTML file

Looking for a way to add a custom timestamp(and maybe some extra info) inside a CSS/HTML file everytime you save the file. Is there an extention for brackets, sublime or dreamweaver that does this, Or perhaps some other way to do this?
Thanks
I think this post will give you a Sublime Text plugin that should do what you ask.
In Brackets, you can configure the snippets extension to insert a timestamp manually, like the answer above for Sublime. Here's how: https://stackoverflow.com/a/18844762/1172352.
Similar to the Sublime answer, it would be a bit trickier to do it automatically every time you save. There's not yet a clean hook in Brackets for pre-save processing. Several extensions get around this by listening for a post-save event and saving quickly a second time. You could probably write a timestamp-auto-inserter extension by borrowing their code for that pattern.
Anything that runs automatically would also need a little extra code to find the old timestamp and replace it -- both the snippets solution here and the Sublime solution above just insert the timestamp wherever the cursor/selection is. A regular expression should do the trick for detection.
You'd also want to screen out other file types. Bringing it all together, it would look something like this for Brackets:
function documentSavedHandler(event, doc) {
// TODO: need a little extra code here to ignore save events triggered
// by ourself, to avoid infinite loop
var langId = doc.getLanguage().getId();
if (langId === "html" || langId === "css") {
var pos = /* use regexp to find old timestamp */;
doc.replaceRange(timestampStr, posStart, posEnd);
CommandManager.execute(Commands.FILE_SAVE);
}
}

generic identifier

as I probably do not describe the problem in the right terms, I was not able to get an answer with google. Please excuse!
In the following code, I would like to replace 'hardcoded' identifier COMMENT with the variable editedField. How to do that?
var editedField:String = event.dataField;
if (model.multipleProcessingData[i][editedInformationProductNO].COMMENT != null{
...
}
Make sure you wrap this in try/catch block for NPE's, as you'll eventually find one with this many [] accessors.
A better, more OOP, would be to have an accessor function on your model that you can pass your data to:
model.getEditedField(i, editedInformatioNProductNO, editedField)
This will make it easier to troubleshoot and add good error messages to your app if things don't turn out like you expected.
var editedField:String = event.dataField;
if (model.multipleProcessingData[i][editedInformationProductNO][editedField] != null{
...
}

Resources