-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom fields #8
Comments
Hi, Maybe the code examples are more helpful: https://blockly-demo.appspot.com/static/demos/custom-fields/index.html |
Thanks for your answer, I have tried the documentation, however it required google-closure library(in code examples goog(***)) somehow and it is not clear how one can integrate it in the global context with angular. I was hoping you have used or seen it somewhere during the development of this plugin and can shed some light on this. |
I think I managed to create a CustomField without google closure. This is not very clean and needs improvement, but it is a proof of concept I guess. Let me know if it helped you. Customfielddeclare var Blockly: any;
export class TestField {
constructor() {
Blockly.TestField = function (opt_value, opt_validator) {
opt_value = this.doClassValidation_(opt_value);
if (opt_value === null) {
opt_value = Blockly.TestField.DEFAULT_VALUE;
} // Else the original value is fine.
Blockly.TestField.superClass_.constructor.call(this, opt_value, opt_validator);
};
Blockly.utils.object.inherits(Blockly.TestField, Blockly.Field);
Blockly.TestField.fromJson = function (options) {
const value = Blockly.utils.replaceMessageReferences(options['value']);
return new Blockly.TestField(value);
};
Blockly.fieldRegistry.register('test_field', Blockly.TestField);
}
} Usage in Blockthis.block.appendDummyInput()
.appendField(new Blockly.TestField(), 'test_field'); Somewhere the constructor needs to be called to register the fieldconst TestField = new TestField(); |
Thanks a lot, it works! I will continue developing a use-case and post it as an example here or in the wiki. |
I will close this for now. If you want to add sth. you can reopen it. |
Hi @dpasdar , |
Hi @evdigitech
This could be placed anywhere, however we have placed it in the same file as our blockly component.
Most importantly you should add the following at the end of the said file :
(TestField is not used anywhere, but it should be done like that here only to invoke the constructor) |
Thank you so much @dpasdar , I have used your code, but getting 2 issues.
|
Hello,
thanks for the great library. I appreciate if you can give me a hint on how I could create/integrate a custom field with/without this library somehow. The examples here use google closure, especially the inheritance doesn't seem to be straight forward without using it. The use-case for us is a typeahead suggestion type of text-input/dropdown, which is sadly not supported out of the box.
I appreciate your help/tips. I would be willing to code/fork/integrate our code into the library once I finished developing it.
The text was updated successfully, but these errors were encountered: