I have a CharField of 400 chars in my model but in the admin built-in form the inputfield is too small. How can I expand the input field in the admin pages?
Thanks.
You can use formfield_overrides to expand your input field:
(https://docs.djangoproject.com/en/1.9/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides)
So, something like this in admin.py:
from django.forms import TextInput, Textarea
from django.db import models
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
...
}
Related
How can i get Model Attribute in Vue?
This is My controller in backend(Spring).
#CrossOrigin(origins = "http://localhost:8080")
#PutMapping("/board/postlist")
public String boardList(Model model){
model.addAttribute("posts", postService.findAllDesc());
model.addAttribute("attrTest", "WHATTHOE");
return "IndexController.update() working";
}
postsis a List.First, I guess my list or sth was wrong. So i add another String attribute attrTest but still in problem...
And this is my vue template.
<b-textarea placeholder="${attrTest}"></b-textarea>
And this is part of my vue script.
<script>
export default {
name: "postList",
data: ()=>({
content:'',
author:'',
})
}
</script>
Screen just display ${attrTest}, in text. It doesn't seem recognize variable.
I been searching many solutions but it doesn't work for me. I tried ${} like jquery but also failed. Maybe my project doesn't have jquery... i can't found jquery in my pakage.json too.
In mustache, i just write {{#posts}} for get model atrribution. Also use Axios result succesfuly but is it impossible to get model attribute with Vue solution? like $attr or sth.
Is it necessary to install jquery?
now I don't no where to start. I tried get posts list all day long. I really need help.
If you're using Thymeleaf as view resolver, try th:placeholder
I am Using Crispy form in Django, But now I like to change the text and style in the form of how to do it?
Suppose I like to change the camp Name to the Only Name, the Text is taken from Django Model, But I like to change here and also I want the text should be on left of text field not on top, How to do it
For horizontal forms see the docs here, same rules apply for bootstrap 4.
https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html?highlight=Inline#bootstrap3-horizontal-forms
To change the fields labels see the django docs
class AuthorForm(ModelForm):
class Meta:
model = Author
fields = ('name', 'title', 'birth_date')
labels = {
'name': 'Writer',
}
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-fields
I need to import a vue js component page into another component by route name.
Anyone can show me the solution.
for example
{ path: '/dashboardadmin', component: require('./components/Dashboard.vue').default, name: 'AdminDashboard' }
this is one of my vue route. I have to import this component into another component by the name AdminDashboard
like this
import AdminDashboard from '*route name*';
Anyone can help me?
thanks in advance
if your parent component is A.vue and the component that you want to import in A.vue is like B.vue then you have to only import your B.vue into A.vue like this
import B from './B.vue' and use it into export default
export default {
components: {
B
},
}
simple
I would like to be able to use Angular2 to do client-side databinding on my server-rendered pages (ASP.Net MVC6).
Is it possible to do this without adding a #view template? Instead of defining it inline or creating an external template, I would like to enclose a block of server-rendered HTML with the app element. This was how I did it in Angular1, as it allows me to choose whether to databind on the server-side or on the client-side.
Thanks.
You can do something similar, that is probably what you want. Take this example:
import {Component, View, bootstrap} from "angular2/angular2";
#Component({
selector: "app"
})
#View({
template: "<content></content>"
})
export class App {
public name: string;
constructor() {
this.name = "MyName";
}
}
bootstrap(App);
The template has a special content
<content></content> that represents the ngTransclude directive. This will allow you to add content inside the app tag:
<app>
<h1>Hello World</h1>
</app>
Unfortunately this is still poorly undocumented and changing so it's hard to tell about the actual limitations or even if this will remain like this.
Regards.
I am creating a component in Joomla 2.5. This component has some options that are defined in its config.xml, so they can be set in the preferences of the component. Now I would like to apply a filter to one of these option fields, using the attribute filter="my_filter".
In the source code of JForm I saw the following lines at the very end of the implementation of JForm::filterField():
if (strpos($filter, '::') !== false && is_callable(explode('::', $filter)))
{
$return = call_user_func(explode('::', $filter), $value);
}
elseif (function_exists($filter))
{
$return = call_user_func($filter, $value);
}
That's what I needed for using a filter function defined by myself!
I managed to do this for form fields used in the views of my component. I defined the filter function as MyComponentHelper::my_filter(), where MyComponentHelper is a helper class which I always load in the very base of my component. And in the form's xml I added filter="MyComponentHelper::my_filter" to the fields that have to be filtered. However... when I am trying to apply the filter function to a form field in my component's preferences, I am not in my own component, but in com_config instead, so my helper class is not available!
So, therefore, my question: where to define my own filter function in such a way that it can be found and called by JForm::filterField() in com_config?? Help is very much appreciated.
May be it is too late, but this topic is only I found about that trouble. May be my solution will be helpfull to someone.
1) Add to tag of .xml form file the attribute 'addfieldpath' like this:
<fieldset name="basic" addfieldpath="PATH_TO_MY_EXTENSION/models/fields">
2) Modify filtered field description like this:
<field
name="MY_FIELD_NAME"
type="myfildtype"
label="MY_FIELD_LABEL"
description="MY_FIELD_DESC"
filter="JFormFieldMyFieldType::filter"
/>
3) Create the file 'PATH_TO_MY_EXTENSION/models/fields/myfildtype.php':
<?php
defined('JPATH_PLATFORM') or die;
JFormHelper::loadFieldClass('text'); // or other standard Joomla! field type
class JFormFieldMyFieldType extends JFormFieldText // or other standard Joomla! field type class
{
protected $type = 'MyFieldType';
public static function filter($value)
{
// filter code
return $value;
}
}
I had to deal with the same issue today. Here is what I did.
Our form field looks like this:
<field name="verwaltungskosten" type="text" class="form-control" size="40" label="Verwaltungskosten" labelclass="col-sm-2
compojoom-control-label"
filter="MyComponentFilterDouble::filter" required="true"/>
As you can see we have a filter. We've specified
MyComponentFilterDouble as class and filter as a method of this class.
If you have a look at libraries/joomla/form/form.php in the
FilterField function toward the end you'll see that the code will try
to execute our custom filter. Now here comes the tricky part. How does
Joomla know where our filters are located? Well, it doesn't! We have
to load our filters in advance. JForm doesn't come with a utility
class that could load a custom filter. I've decided to load our
Filters in our model in the getForm function. As you know each model
that extends from JModelAdmin should have a getForm function. This
function makes sure that we are loading the correct form from a .xml
file. So in this function just before I load the form I did:
JLoader::discover('MyComponentFilter', JPATH_ADMINISTRATOR . '/components/com_mycomponent/models/forms/filters');
The discover method will make sure to auto load our class when we need
it. This way it will be available to our form.
And there we go! Now when our model validates the form. It actually
always first performs filtering on the data. Now in our custom filter
we can modify the data and pass it back for validation. It's that
easy!
The above text is in quotes because I took it from my blogpost about that same issue over here: https://compojoom.com/blog/entry/custom-filtering-for-jform-fields
I think what you're asking about is actually adding custom validation to one of your form fields. If that's the case you actually need to be looking at adding server-side validation in addition to adding configuration. Pay particular attention to the 'addrulepath' in the example under the heading "Using configuration parameters as default value". You'll most likely end up extending JFormRule, of which I've included a very stripped-down example below.
<?php
/** headers */
defined('JPATH_PLATFORM') or die; // Joomla only
class JFormRuleCustom extends JFormRule
{
public $type = 'Custom';
public function test(&$element, $value, $group = null, &$input = null, &$form = null) {
return /* true for passed validation, false for failed validation */
}
}
When you've got that down you can add the validation "custom" to your form fields like so:
<field
name="pw1"
type="password"
label="COM_NEWUSER_UPDATE_LABEL_PASSWORD1"
description="COM_NEWUSER_UPDATE_DESCRIPTION_PASSWORD1"
message="COM_NEWUSER_UPDATE_ERROR_PASSWORD1"
size="40"
required="true"
validate="custom"
minlength="5"
maxlength="20"
specials="!##$%^&*"
/>
Hopefully that answers your question and didn't go totally off-topic.