How does the MenuBar object at the bottom of Form work? - codenameone

I'm struggling with the MenuBar at the bottom of a form - the one indicated by the codenameone Javadocs here:
I can't seem to find an example, but from what I can tell, something like the following should work:
public void start() {
if(current != null){
current.show();
return;
}
Form hi = new Form("Welcome");
MenuBar menubar = hi.getMenuBar();
Command test = Command.create("TEST",null,(e)->{
Log.p("test clicked");
});
menubar.addCommand(test);
hi.show();
}
However, I don't get a MenuBar.
Obviously I'm missing something basic here - can anyone show me what I'm doing wrong?

The menu bar logic is a bit old, you don't need to define that or use it. Modern Codename One applications use the Toolbar to place elements and usually add their content to the top of the Form. I'll update the JavaDoc to reflect that.
If you are interested in having a menu at the bottom of the form just do this:
Form myForm = new Form("With Menu at Bottom", new BorderLayout());
Container content = new Container(...);
myForm.add(BorderLayout.CENTER, content);
myForm.add(BorderLayout.SOUTH,
GridLayout.encloseIn(4, menuButton1, menuButton2, menuButton3, menuButton4);
Just add your real content to content and create the buttons any way you like.

You didn't assign a MenuBar to the form yet. First, you must create one and then assign it using the function
setMenuBar(MenuBar menubar)

Related

How can I detect the state of Content at View startup?

Lets assume I have created my own custom view for a Link content type. When the user adds a 2sxc Content app to a Pane, then picks the Content Type (Link) then my custom View, when it first starts up, how can I detect that a) the View does not use a Demo item vs. b) the View uses a demo item and is showing the Demo item vs. c) its not the first time and there is a real user added Content (Entity) in place?
I have done stuff like this for the a) case:
var link = AsDynamic(Data["Default"]).First();
then checked if it was null, but it looks like my View code never executes and instead I just see, "No demo item exists for the selected template."
If I do assign a demo, is there a more elegant way to know that the Entity I am handed as Content.First() or Data["Default"]).First() is a Demo item and now a user created Entity? Currently I am hard-coding the EntityId in the template and testing for that.
The template system does not render the template if there is no demo item (unless it's a template without a content-type).
When we need this, we have two ways
give the demo item a unique value in one of the fields and check for that in the template
check the demo-item ID on GUID and check for that (Content.EntityGuid == ...)
IsDemoItem property added in 2sxc 10.06
Dynamic Entity
If a Content Editor "Hides" the only Content Item, the anonymous user will then see a Demo Item where the item was. This is confusing and unexpected from the Content Editor's point of view (as well as the public/anonymous user). If anyone else runs in to it, here is the simple code snippet to add to the start of your view. Basically, if the current user is not logged in and the item to display is a demo item, exit the View w/o displaying anything.
if(!Request.IsAuthenticated) {
if(Content.IsDemoItem ?? false) {
return;
}
}
Best to put it near the start of your first #{} Razor block.
Note: this will not throw an error in 2sxc prior to 10.6.x (because of the "?? false"), but it will not work either.

How to make quill editor required?

How to make the quill editor field required? The editor gets rendered into a div, but it isn't clear if there is a way to make the field/editor required when the form submits.
As you wrote, Quill works with a div and not with a form element so it can't help you with form validation.
You'll need to check manually if the editor's content is empty, prevent the user from submitting the form and show a message that this field is required.
You can copy quill contents to a hidden input element before submitting the form as shown in this example.
A custom form control is also a good way to go. You can try to workaround with Quill's event handler and getting the value of the form.
Then a custom form validator is also possible.
Check : https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html
I've been trying to work around exactly this problem too today, using Python for back-end and a hidden form-field (name='editor') to get the value from the quill container to the back-end. Ended up with not actually really a validator but working about the same:
if request.form['editor'] == '\"<p><br></p>\"':
flash("You cannot send in empty posts!")
return redirect(CURRENT PAGE)
else:
CODE EXECUTED IF EDITOR IS NOT EMPTY
Not sure what you're doing with the input on the editor or whether you're even using Python for backend but I hope this helps. "<p><br></p>" is what the console told me the standard input on empty submission was when getting the information out of the editor.
Good luck!
const yourText = '<div><br></div>';
const htmlTagsToRemove = ['<div>', '</div>', '<br>'];
function removeHtmlTags(data) {
let text = data;
htmlTagsToRemove.forEach(it => {
text = text.replace(it, '');
});
return text;
}
const newText = removeHtmlTags(yourText);
console.log(newText);

Override custom content page markup Drupal 7

Although I've seen some 'clean' answers on this topic here, it still doesn't work in my case, which is the following: being in Drupal 7 with a completely customized theme, I have created a custom content with the machine name cco_product. I want to override the page markup for the page generated for this content type. I have tried, as per the documentation,
page--cco_product.tpl.php in the tmemes folder, based on /module/system/page.tpl.php, but my Hello world on top of this file doesn't show up.
Thanks for help
First, try clean your cache, if did't help, i can advise to look into the an array of templates for your page. Maybe one of your modules or your custom theme overrides array of templates like this:
function MYTHEME_preprocess_page(&$variables, $hook) {
//Add multiple suggestions for pages based on Node
if(arg(1) == 3) { //For node 3
$variables['theme_hook_suggestions'][] = 'page__contact';
} if(arg(1) == 4) { //For node 4
$variables['theme_hook_suggestions'][] = 'page__about';
}
}

Load layout element based on view in CakePHP

I have a sidebar defined in my main layout which most of the time will display the login form. After the user is logged in I need to remove that form and replace it with user data. I also need to change that sidebar when viewing the support section to show the sub-sections.
Do I need to move the element loading to each view or is there another way?
Thanks in advance,
Denis
Bottom line is you're gonna need an if($supportpage){} elseif($loggedin){} else{} block. If you don't want to put it in your layout file you could create an element for each option and then set() the correct one from the app_controller:
if ($supportpage) $sidebar = 'support';
elseif ($loggedin) $sidebar = 'loggedin';
else $sidebar = 'notloggedin';
$this->set(compact($sidebar));
And then put $this->element($sidebar) in your layout.

How to use .NET TextBoxRenderer with TextBoxState.Hot to draw a hot text box?

i am trying to use TextBoxRenderer to render a "hot" text box:
TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot);
except that it doesn't work, it doesn't render the text box as hot.
TextBoxState.Selected doesn't render as selected
TextBoxState.Hot doesn't render as hot
How do i make TextBoxRenderer.DrawTextBox(..., Hot) render as Hot?
Related but different question:
How do i make TextBoxRenderer.DrawTextBox(..., Selected) render as Selected?
It seems that TextBoxRenderer uses EP_BACKGROUNDWITHBORDER, whereas EP_EDITBORDER_NOSCROLL is typically used by TextBox controls[1].
if (VisualStyleRenderer.IsSupported)
{
// Use the text control's focus rectangle.
// EP_EDITBORDER_NOSCROLL, EPSN_FOCUSED
VisualStyleElement element = VisualStyleElement.CreateElement("EDIT", 6, 3);
if (VisualStyleRenderer.IsElementDefined(element))
{
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
renderer.DrawBackground(e.Graphics, ClientRectangle);
}
}
(It's tempting to try to get the element from VisualStyleElement but there's no nested class for EP_EDITBORDER_NOSCROLL. So numeric constants 6 and 3 it is.)

Resources