Why can't add js() to a dropdown field on a form? - atk4

I just keep getting this error:
Method js is not defined neither in controller, nor in its Model.
Thi is my page
class page_alumnos_inscribir extends Page {
function init(){
parent::init();
$page=$this;
$model=$this->add('Model_Alumno')->loadData($_GET['id']);
$h=$this->add('H3')->set($model->get('name').' ( '.$model->get('grado').$model->get('nivel'). ' )');
$f=$page->add('Form');
$r=$f->addField('dropdown','Inscribir al Curso')->setModel('Curso');
$r->js('change')->univ()->alert('orale');
$s=$f->addField('line','montoPeriodo');
}
}

You wrote a wrong chain. Set model returns the added model, you need the created field instead. Try to do it in this way:
$r=$f->addField('dropdown','Inscribir al Curso');
$r->setModel('Curso');
$r->js('change')->univ()->alert('orale');

Related

joining two models and show theme in one grid

I have two models:
A) Model ticket:
class Model_Ticket extends Model_Table {
public $table='ticket';
function init(){
parent::init();
$this->addField('subject');
$this->addField('content')->type("text");
}
}
B) Subticket:
class Model_Subticket extends Model_Table {
public $table='subticket';
function init(){
parent::init();
$this->addField('content')->type("text");
$this->addField('ticket_id')->type("int");
}
}
each ticket has many subtickets.
now I want to have a grid which the first row of that should be the "Content" of main ticket and other rows should be the "Content" of subtickets of that ticktet.
how can we do that?
thanks.
First create the grid which would display sub tickets, load them properly etc. Next look inside Grid's render() method. As you follow the execution, you'll find the following call chain:
grid::render()
CompleteLister::renderRows()
CompleteLister::renderDataRows()
You would need to override the normal rendering, fill out $this->current_row yourself and then call renderDataRows once before passing execution to parent::renderRows();
This will pop an extra row inside your Grid.

How to save data POSTed from From into database not using Form->setModel()

I know that's kinda simple and lame question, but still.
I have a Form which should not show all Model fields, but only some of them. That's why I can't use Form->setModel($m), because that'll automatically add all fields into Form.
So I add Model into page, then add form into page and then use form->importFields like this:
$m = $p->add('Model_Example');
$f = $p->add('Form');
//$f->setModel($m); // can't use this because that'll import all model fields
$f->importFields($m,array('id','description'));
$f->addSubmit('Save');
What I don't understand in this situation is - how to save this data in database, because $f->update() in onSubmit event will not work. Basically nothing I tried will work because Form have no associated Model (with setModel).
How about this way?
$your_form->setModel($model,array('name','email','age'));
I have solution for mixed form. Add custom form fields in form init and manipulate with them by hooks ('afterLoad','beforeSave')
In this case you can use setModel() method
$form->setModel('Some_Model',array('title','description'));
class Form_AddTask extends Form {
function init(){
parent::init();
$this->r=$this->addField('autocomplete/basic','contact');
$this->r->setModel('ContactEntity_My');
}
function setModel($model,$actual_fields=undefined){
parent::setModel($model,$actual_fields);
$this->model->addHook('afterLoad',array($this,'setContactId'));
$this->model->addHook('beforeSave',array($this,'setContactEntityId'));
return $this->model;
}
// set saved value for editing
function setContactId() {
$this->r->set($this->model->get('contact_entity_id'));
}
function setContactEntityId() {
$this->model->set('contact_entity_id',$this->get('contact'));
}
}
There is a hook 'validate' as well in Form_Basic::submitted(), so you can add
$this->addHook('validate',array($this,'validateCustomData'));
and validate your data in Form::validateCustomData()
Why not set the fields to hidden in the model?
I.e.:
class Model_Example extends Model_Table {
public $table='assessment';
function init() {
parent::init();
$grant->addField('hidden_field')->hidden(true);
}
}
And then:
$m = $p->add('Model_Example');
$f = $p->add('Form');
$f->setModel($m);

Unable to bind Component attribute with controller

I am trying to develop a visualforce custom component which takes an attribute from a visual force page. I need to access that attribute in controller's Constructor so that i can brings some records from database and i need to display those records in the Component. But problem is that i am not getting Attribute value in Controller.
See the below code to understand the problem clearly..
Controller :
public with sharing class AdditionalQuestionController {
public String CRFType {get;set;}
public AdditionalQuestionController () {
system.debug('CRFType : '+CRFType);
List<AdditoinalQuestion__c> lstAddQues = [Select AddQues__c from AdditoinalQuestion__c wehre CRFType = :CRFType];
system.debug('lstAddQue : '+lstAddQue);
}
}
Component :
<apex:component controller="AdditionalQuestionController" allowDML="true">
<apex:attribute name="CRFType" description="This is CRF Type." type="String" required="true" assignTo="{!CRFType}" />
<apex:repeat value="{!lstAddQue}" var="que">
{!que}<br />
</apex:repeat>
</apex:component>
VisualForce page :
<apex:page >
<c:AdditionalQuestionComponent CRFType="STE" />
</apex:page>
Thanks,
Vivek
I believe the issue here is that you're expecting the member variable to have a value inside the constructor — the snag is that the instance of the class is being constructed! It doesn't exist yet and so there is no way that a non-static member variable could be given a value prior.
Instead of doing the query in your constructor, specify your own getter for lstAddQue and do the query in there when you need the data. Of course, you may want to cache the value so that the query is not run every time, but from the looks of things that won't be relevant here.
Setter methods on the attributes in a VF component appear to be called after the constructor has returned, unfortunately. Here's an alternative solution for your controller that uses a getter method to populate your list (which would be called after your CRFType member variable has been set):
public with sharing class AdditionalQuestionController {
public String CRFType {set;}
public AdditionalQuestionController () {
system.debug('CRFType : '+CRFType); // this will be null in the constructor
}
public List<AdditoinalQuestion__c> getLstAddQue() {
system.debug('CRFType : '+CRFType); // this will now be set
List<AdditoinalQuestion__c> lstAddQues = [Select AddQues__c from AdditoinalQuestion__c wehre CRFType = :CRFType];
system.debug('lstAddQue : '+lstAddQue);
return lstAddQue;
}
}

Adding fields on the fly

I have a form with a table source, the form has a few fields (product, quantity)
I'm thinking to add a button that allows me to add another "line" with product, quantity.... and so on, because I don't know how many items I need to add.
Which is the best approach ?
maybe removing the StaticSource('') and implementing on the submit the inserts ?
Thanks
Alejandro
class page_yourpage extends Page {
function init(){
parent::init();
$this->add("CRUD")->setModel("Product");
}
}
class Model_Product extends Model_Table {
$entity_code = "yourtable";
function init(){
parent::init();
$this->addField("product_id")->refModel("Model_Product");
$this->addField("quantity");
}
}
that's it. (did not test in browser);

Why do I get Unable to include RenderObjectSuccess.php error when using inline in grid?

I'm setting up a grid with an inline field, pretty much the sames than in the examples in the demo, but I just keep getting error: Unable to include RenderObjectSuccess.php when chaning the value in the inline field. What a I doing wrong?
class page_alumnos_pago extends Page {
function init(){
parent::init();
$this->api->stickyGET('id');
$mAlumno=$this->add('Model_Alumno')->loadData($_GET['id']);
$g = $this->add('Grid');
$g->addColumn('date','fechaVencimiento');
$g->addColumn('text','concepto');
$g->addColumn('money','monto');
$g->addColumn('inline','temp_pago');
$g->setSource('programaPago');
$g->dq->where('alumno_id',$_GET['id']);
}
}
This is my ProgramaPago model:
class Model_ProgramaPago extends Model_Table {
public $entity_code='programaPago';
function init(){
parent::init();
$this->addField('alumno_id')->caption('Alumno')->refModel('Model_Alumno')->mandatory(true);
$this->addField('fechaVencimiento')->caption('Fecha de Vencimiento')->type('date')->mandatory(true);
$this->addField('monto')->caption('Monto')->type('money')->mandatory(true);
$this->addField('concepto')->caption('concepto')->type('text')->mandatory(true);
}
}
Eh, that's a bug.
https://github.com/atk4/atk4/issues/37
fix: https://github.com/atk4/atk4/commit/3694996
Please let me know if the fix works.

Resources